feat: add party user gender field to schema and implement event joining functionality with gender tracking
This commit is contained in:
@@ -1291,4 +1291,5 @@ model PartyUser {
|
||||
zipCode String @default("")
|
||||
//
|
||||
rank String @default("user")
|
||||
sex String @default("")
|
||||
}
|
||||
|
@@ -58,6 +58,7 @@ async function partyUser() {
|
||||
status: STATUS[0],
|
||||
role: ROLE[0],
|
||||
isVerified: true,
|
||||
sex: 'F',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -78,6 +79,7 @@ async function partyUser() {
|
||||
isVerified: true,
|
||||
avatarUrl: 'https://images.unsplash.com/photo-1619970096024-c7b438a3b82a',
|
||||
rank: 'user',
|
||||
sex: 'M',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -112,6 +114,7 @@ async function partyUser() {
|
||||
role: ROLE[Math.floor(Math.random() * ROLE.length)],
|
||||
status: STATUS[Math.floor(Math.random() * STATUS.length)],
|
||||
isVerified: true,
|
||||
sex: i % 2 ? 'F' : 'M',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@@ -0,0 +1,58 @@
|
||||
// src/app/api/product/createEvent/route.ts
|
||||
//
|
||||
// PURPOSE:
|
||||
// create product to db
|
||||
//
|
||||
// RULES:
|
||||
// T.B.A.
|
||||
//
|
||||
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
import _ from 'lodash';
|
||||
|
||||
import { STATUS, response, handleError } from 'src/utils/response';
|
||||
|
||||
import { getEventItemById } from 'src/app/services/eventItem.service';
|
||||
import { getPartyUserByEmail } from 'src/app/services/party-user.service';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
***************************************
|
||||
* POST - Events
|
||||
***************************************
|
||||
*/
|
||||
export async function POST(req: NextRequest) {
|
||||
// logger('[Event] list', events.length);
|
||||
const { data } = await req.json();
|
||||
const { eventItemId, email } = data;
|
||||
|
||||
try {
|
||||
const eventItem = await getEventItemById(eventItemId);
|
||||
const partyUser = await getPartyUserByEmail(email);
|
||||
|
||||
if (partyUser) {
|
||||
if (eventItem && eventItem?.joinMembers) {
|
||||
const foundJoined = _.find(eventItem.joinMembers, { email });
|
||||
|
||||
if (foundJoined) {
|
||||
console.log('user joined event already, skipping');
|
||||
} else {
|
||||
const { sex } = partyUser;
|
||||
eventItem.joinMembers.push({ email, sex });
|
||||
|
||||
await prisma?.eventItem.update({
|
||||
where: { id: eventItem.id },
|
||||
data: { joinMembers: JSON.parse(JSON.stringify(eventItem.joinMembers)) },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response({ result: 'joined' }, STATUS.OK);
|
||||
} catch (error) {
|
||||
console.log({ hello: 'world', data });
|
||||
return handleError('Event - Create', error);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
###
|
||||
|
||||
# username and password ok
|
||||
|
||||
POST http://localhost:7272/api/event/partyUserJoinEvent
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"eventItemId": "e99f09a7-dd88-49d5-b1c8-1daf80c2d7b01",
|
||||
"email": "alice@prisma.io"
|
||||
}
|
||||
}
|
@@ -47,6 +47,10 @@ async function getEvent(eventId: string): Promise<EventItem | null> {
|
||||
return prisma.eventItem.findFirst({ where: { id: eventId } });
|
||||
}
|
||||
|
||||
async function getEventItemById(eventId: string): Promise<EventItem | null> {
|
||||
return prisma.eventItem.findFirst({ where: { id: eventId } });
|
||||
}
|
||||
|
||||
// async function createNewEvent(createForm: CreateEvent) {
|
||||
// return prisma.event.create({ data: createForm });
|
||||
// }
|
||||
@@ -68,4 +72,5 @@ export {
|
||||
// updateEvent,
|
||||
// deleteEvent,
|
||||
// createNewEvent,
|
||||
getEventItemById,
|
||||
};
|
||||
|
@@ -41,6 +41,12 @@ async function getPartyUser(partyUserId: string): Promise<PartyUser | null> {
|
||||
});
|
||||
}
|
||||
|
||||
async function getPartyUserByEmail(email: string): Promise<PartyUser | null> {
|
||||
return prisma.partyUser.findUnique({
|
||||
where: { email },
|
||||
});
|
||||
}
|
||||
|
||||
async function getUserById(id: string): Promise<User | null> {
|
||||
return prisma.user.findFirst({ where: { id } });
|
||||
}
|
||||
@@ -70,6 +76,8 @@ export {
|
||||
updatePartyUser,
|
||||
deletePartyUser,
|
||||
//
|
||||
getPartyUserByEmail,
|
||||
//
|
||||
type CreateUser,
|
||||
type UpdateUser,
|
||||
//
|
||||
|
@@ -73,7 +73,7 @@ interface StateProps {}
|
||||
|
||||
interface DispatchProps {}
|
||||
|
||||
interface EventDetailProps extends OwnProps, StateProps, DispatchProps {}
|
||||
interface PageProps extends OwnProps, StateProps, DispatchProps {}
|
||||
|
||||
const showJoinedMembers = (joinMembers: Record<string, any>[]) => {
|
||||
const avatars = joinMembers.map((jm) => jm.avatar);
|
||||
@@ -90,7 +90,7 @@ const showJoinedMembers = (joinMembers: Record<string, any>[]) => {
|
||||
);
|
||||
};
|
||||
|
||||
const EventDetail: React.FC<EventDetailProps> = ({ event_detail }) => {
|
||||
const EventDetail: React.FC<PageProps> = ({ event_detail }) => {
|
||||
const router = useIonRouter();
|
||||
|
||||
const [showPopover, setShowPopover] = useState(false);
|
||||
|
Reference in New Issue
Block a user