feat: add party user gender field to schema and implement event joining functionality with gender tracking
This commit is contained in:
@@ -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,
|
||||
//
|
||||
|
Reference in New Issue
Block a user