Skip to content

Commit 9e2f331

Browse files
committed
Created route to get all rsvps for an event
1 parent 440fae7 commit 9e2f331

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/api/routes/rsvp.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { FastifyPluginAsync } from "fastify";
22
import rateLimiter from "api/plugins/rateLimiter.js";
33
import { withRoles, withTags } from "api/components/index.js";
4+
import { QueryCommand } from "@aws-sdk/client-dynamodb";
5+
import { unmarshall } from "@aws-sdk/util-dynamodb";
46
import { getUserOrgRoles } from "api/functions/organizations.js";
57
import {
68
UnauthenticatedError,
@@ -11,6 +13,15 @@ import * as z from "zod/v4";
1113
import { verifyUiucAccessToken } from "api/functions/uin.js";
1214
import { checkPaidMembership } from "api/functions/membership.js";
1315
import { 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

1526
const 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

72118
export default rsvpRoutes;

0 commit comments

Comments
 (0)