logic for eventGuests
This commit is contained in:
@@ -117,4 +117,47 @@ export const mutations = {
|
||||
})
|
||||
},
|
||||
|
||||
async addEventGuest({
|
||||
eventId,
|
||||
guestBookEntryId,
|
||||
}: {
|
||||
eventId: string,
|
||||
guestBookEntryId: string,
|
||||
}) {
|
||||
return await prisma.eventGuest.create({
|
||||
data: {
|
||||
eventId,
|
||||
guestBookEntryId,
|
||||
rsvp: 'PENDING'
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async updateEventGuestRsvp({
|
||||
eventId,
|
||||
guestBookEntryId,
|
||||
rsvp,
|
||||
}: {
|
||||
eventId: string;
|
||||
guestBookEntryId: string;
|
||||
rsvp: 'YES' | 'NO' | 'PENDING';
|
||||
}) {
|
||||
return await prisma.eventGuest.update({
|
||||
where: {
|
||||
eventId_guestBookEntryId: { eventId, guestBookEntryId }, // compound unique constraint
|
||||
},
|
||||
data: {
|
||||
rsvp,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
async removeEventGuest(eventId: string, guestBookEntryId: string) {
|
||||
return await prisma.eventGuest.delete({
|
||||
where: {
|
||||
eventId_guestBookEntryId: { eventId, guestBookEntryId },
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
};
|
||||
@@ -16,6 +16,48 @@ export const queries = {
|
||||
return allEvents;
|
||||
},
|
||||
|
||||
async fetchEventGuests(eventId: string) {
|
||||
return await prisma.eventGuest.findMany({
|
||||
where: { eventId },
|
||||
include: {
|
||||
guestBookEntry: true,
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
guestBookEntry: {
|
||||
lName: 'asc',
|
||||
},
|
||||
},
|
||||
{
|
||||
guestBookEntry: {
|
||||
fName: 'asc'
|
||||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
},
|
||||
|
||||
async fetchAvailableGuestBookEntriesForEvent(eventId: string) {
|
||||
const invitedGuests = await prisma.eventGuest.findMany({
|
||||
where: { eventId },
|
||||
select: { guestBookEntryId: true }
|
||||
});
|
||||
|
||||
const excludeIds = invitedGuests.map(g => g.guestBookEntryId);
|
||||
|
||||
return prisma.guestBookEntry.findMany({
|
||||
where: {
|
||||
id: {
|
||||
notIn: excludeIds,
|
||||
},
|
||||
},
|
||||
orderBy: [
|
||||
{ lName: 'asc' },
|
||||
{ fName: 'asc' }
|
||||
]
|
||||
})
|
||||
},
|
||||
|
||||
async singleEvent(id: string) {
|
||||
const event = await prisma.event.findUnique({
|
||||
where: { id },
|
||||
|
||||
Reference in New Issue
Block a user