11import { FastifyPluginAsync } from "fastify" ;
22import rateLimiter from "api/plugins/rateLimiter.js" ;
33import { withRoles , withTags } from "api/components/index.js" ;
4+ import { QueryCommand } from "@aws-sdk/client-dynamodb" ;
5+ import { unmarshall } from "@aws-sdk/util-dynamodb" ;
46import { getUserOrgRoles } from "api/functions/organizations.js" ;
57import {
68 UnauthenticatedError ,
@@ -11,6 +13,15 @@ import * as z from "zod/v4";
1113import { verifyUiucAccessToken } from "api/functions/uin.js" ;
1214import { checkPaidMembership } from "api/functions/membership.js" ;
1315import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi" ;
16+ import { genericConfig } from "common/config.js" ;
17+
18+ const rsvpItemSchema = z . object ( {
19+ eventId : z . string ( ) ,
20+ userId : z . string ( ) ,
21+ isPaidMember : z . boolean ( ) ,
22+ createdAt : z . string ( ) ,
23+ } ) ;
24+ const rsvpListSchema = z . array ( rsvpItemSchema ) ;
1425
1526const rsvpRoutes : FastifyPluginAsync = async ( fastify , _options ) => {
1627 await fastify . register ( rateLimiter , {
@@ -67,6 +78,41 @@ const rsvpRoutes: FastifyPluginAsync = async (fastify, _options) => {
6778 } ;
6879 } ,
6980 ) ;
81+ fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . get (
82+ "/:orgId/event/:eventId" ,
83+ {
84+ schema : withTags ( [ "RSVP" ] , {
85+ summary : "Get all RSVPs for an event." ,
86+ params : z . object ( {
87+ eventId : z . string ( ) . min ( 1 ) . meta ( {
88+ description : "The previously-created event ID in the events API." ,
89+ } ) ,
90+ orgId : z . string ( ) . min ( 1 ) . meta ( {
91+ description : "The organization ID the event belongs to." ,
92+ } ) ,
93+ } ) ,
94+ headers : z . object ( {
95+ "x-uiuc-token" : z . jwt ( ) . min ( 1 ) . meta ( {
96+ description :
97+ "An access token for the user in the UIUC Entra ID tenant." ,
98+ } ) ,
99+ } ) ,
100+ } ) ,
101+ } ,
102+ async ( request , reply ) => {
103+ const commnand = new QueryCommand ( {
104+ TableName : genericConfig . EventsDynamoTableName ,
105+ IndexName : "EventIdIndex" ,
106+ KeyConditionExpression : "eventId = :eid" ,
107+ ExpressionAttributeValues : {
108+ ":eid" : { S : request . params . eventId } ,
109+ } ,
110+ } ) ;
111+ const response = await fastify . dynamoClient . send ( commnand ) ;
112+ const items = response . Items ?. map ( ( item ) => unmarshall ( item ) ) || [ ] ;
113+ return reply . send ( items as z . infer < typeof rsvpListSchema > ) ;
114+ } ,
115+ ) ;
70116} ;
71117
72118export default rsvpRoutes ;
0 commit comments