Skip to content

Commit 414468e

Browse files
committed
feat: add endpoint to retrieve RSVPs for an event by host/co-host
1 parent b656fb9 commit 414468e

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/routes/inviteRoutes.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
getEventRsvpSummary,
1111
getEventGuestList,
1212
bulkCreateInvites,
13-
sendWhatsappInvite
13+
sendWhatsappInvite,
14+
getEventRsvps
1415
} from '../services/inviteService';
1516
import { verifyIdToken } from '../middleware/verifyIdToken';
1617
import { isEventHostOrCoHost } from '../services/guestService';
@@ -94,6 +95,31 @@ router.post('/bulk/:eventId', verifyIdToken, async (req: Request, res: Response)
9495
}
9596
});
9697

98+
// Get all RSVPs for an event (host/co-host only)
99+
router.get('/rsvps/:eventId', verifyIdToken, async (req: Request, res: Response) => {
100+
try {
101+
const { eventId } = req.params;
102+
const userId = req.userId;
103+
if (!userId) {
104+
return res.status(401).json({ message: 'Unauthorized' });
105+
}
106+
107+
const result = await getEventRsvps(eventId, userId);
108+
109+
if (!result.success) {
110+
if (result.error?.includes('Access denied')) {
111+
return res.status(403).json({ message: result.error });
112+
}
113+
return res.status(400).json({ message: result.error });
114+
}
115+
116+
res.status(200).json({ rsvps: result.rsvps });
117+
} catch (error) {
118+
console.error(error);
119+
res.status(500).json({ message: 'Internal Server Error' });
120+
}
121+
});
122+
97123
// Get authenticated user's RSVP for a specific event
98124
router.get('/rsvp/event/:eventId', verifyIdToken, async (req: Request, res: Response) => {
99125
try {

src/services/inviteService.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,53 @@ export const bulkCreateInvites = async (eventId: string, invitesData: Array<{
965965

966966
// ===== HOST/CO-HOST ENDPOINTS =====
967967

968+
export const getEventRsvps = async (eventId: string, userId: string) => {
969+
try {
970+
// Verify user is host or co-host
971+
const isAuthorized = await isEventHostOrCoHost(userId, eventId);
972+
if (!isAuthorized) {
973+
return {
974+
success: false,
975+
error: 'Access denied. Only hosts and co-hosts can view RSVPs.'
976+
};
977+
}
978+
979+
const guests = await prisma.guest.findMany({
980+
where: { event_id: eventId },
981+
include: {
982+
user: {
983+
select: {
984+
id: true,
985+
name: true,
986+
mobile_number: true,
987+
email: true,
988+
profile_pic: true
989+
}
990+
},
991+
group: {
992+
select: {
993+
id: true,
994+
name: true
995+
}
996+
}
997+
},
998+
orderBy: {
999+
name: 'asc'
1000+
}
1001+
});
1002+
1003+
return {
1004+
success: true,
1005+
rsvps: guests
1006+
};
1007+
} catch (error: unknown) {
1008+
return {
1009+
success: false,
1010+
error: error instanceof Error ? error.message : 'Failed to get event RSVPs'
1011+
};
1012+
}
1013+
};
1014+
9681015
// Get all RSVPs for a user across events (protected)
9691016
export const getUserRsvps = async (userId: string) => {
9701017
try {

0 commit comments

Comments
 (0)