Skip to content

Commit 28a8902

Browse files
devksingh4krivera28
andcommitted
scaffold the check membership route
Co-authored-by: krivera28 <[email protected]>
1 parent e0b7956 commit 28a8902

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

src/api/functions/validation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ export function validateEmail(email: string): boolean {
55
const result = emailSchema.safeParse(email);
66
return result.success;
77
}
8+
9+
export function validateNetId(netId: string): boolean {
10+
// TODO: write this function to check if the netid matches this regex: [a-zA-Z0-9\-]+
11+
return true;
12+
}

src/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import vendingPlugin from "./routes/vending.js";
1717
import * as dotenv from "dotenv";
1818
import iamRoutes from "./routes/iam.js";
1919
import ticketsPlugin from "./routes/tickets.js";
20+
import membershipPlugin from "./routes/membership.js";
2021
dotenv.config();
2122

2223
const now = () => Date.now();
@@ -75,6 +76,7 @@ async function init() {
7576
api.register(organizationsPlugin, { prefix: "/organizations" });
7677
api.register(icalPlugin, { prefix: "/ical" });
7778
api.register(iamRoutes, { prefix: "/iam" });
79+
api.register(membershipPlugin, { prefix: "/membership" });
7880
api.register(ticketsPlugin, { prefix: "/tickets" });
7981
if (app.runEnvironment === "dev") {
8082
api.register(vendingPlugin, { prefix: "/vending" });

src/api/routes/membership.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { validateNetId } from "api/functions/validation.js";
2+
import { FastifyPluginAsync } from "fastify";
3+
import { ValidationError } from "zod-validation-error";
4+
5+
const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
6+
fastify.get<{
7+
Body: undefined;
8+
Querystring: { netId: string };
9+
}>("/:netId", {
10+
schema: {
11+
querystring: {
12+
type: "object",
13+
properties: {
14+
netId: {
15+
type: "string",
16+
},
17+
},
18+
},
19+
},
20+
}, async (request, reply) => {
21+
const netId = (request.params as Record<string, string>).netId;
22+
if (!validateNetId(netId)) { // TODO: implement the validateNetId function
23+
throw new ValidationError(`${netId} is not a valid Illinois NetID!`);
24+
}
25+
// TODOs below:
26+
// 1. Check Dynamo table infra-core-api-membership-logs to see if `[email protected]` has an entry. if yes, return the json {netid: netid, isPaidMember: true}
27+
// 2. Call checkGroupMembership(token, `[email protected]`, groupId). if yes, {netid: netid, isPaidMember: result}
28+
// 3. If AAD says they're a member, insert this yes result into infra-core-api-membership-logs so that it's cached for the next time.
29+
// request.log.debug(`Checking the group ID ${fastify.environmentConfig.PaidMemberGroupId} for membership`)
30+
reply.send(`Hello, ${netId}!`);
31+
});
32+
};
33+
34+
export default membershipPlugin;

src/common/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type ConfigType = {
1616
UserRoleMapping: UserRoleMapping;
1717
ValidCorsOrigins: ValueOrArray<OriginType> | OriginFunction;
1818
AadValidClientId: string;
19+
PaidMemberGroupId: string;
1920
};
2021

2122
type GenericConfigType = {
@@ -79,6 +80,7 @@ const environmentConfig: EnvironmentConfigType = {
7980
/^https:\/\/(?:.*\.)?acmuiuc\.pages\.dev$/,
8081
],
8182
AadValidClientId: "39c28870-94e4-47ee-b4fb-affe0bf96c9f",
83+
PaidMemberGroupId: "9222451f-b354-4e64-ba28-c0f367a277c2"
8284
},
8385
prod: {
8486
GroupRoleMapping: {
@@ -109,6 +111,7 @@ const environmentConfig: EnvironmentConfigType = {
109111
/^https:\/\/(?:.*\.)?acmuiuc\.pages\.dev$/,
110112
],
111113
AadValidClientId: "5e08cf0f-53bb-4e09-9df2-e9bdc3467296",
114+
PaidMemberGroupId: "172fd9ee-69f0-4384-9786-41ff1a43cf8e"
112115
},
113116
};
114117

0 commit comments

Comments
 (0)