File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import vendingPlugin from "./routes/vending.js";
1717import * as dotenv from "dotenv" ;
1818import iamRoutes from "./routes/iam.js" ;
1919import ticketsPlugin from "./routes/tickets.js" ;
20+ import membershipPlugin from "./routes/membership.js" ;
2021dotenv . config ( ) ;
2122
2223const 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" } ) ;
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff 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
2122type GenericConfigType = {
@@ -79,6 +80,7 @@ const environmentConfig: EnvironmentConfigType = {
7980 / ^ h t t p s : \/ \/ (?: .* \. ) ? a c m u i u c \. p a g e s \. d e v $ / ,
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 / ^ h t t p s : \/ \/ (?: .* \. ) ? a c m u i u c \. p a g e s \. d e v $ / ,
110112 ] ,
111113 AadValidClientId : "5e08cf0f-53bb-4e09-9df2-e9bdc3467296" ,
114+ PaidMemberGroupId : "172fd9ee-69f0-4384-9786-41ff1a43cf8e"
112115 } ,
113116} ;
114117
You can’t perform that action at this time.
0 commit comments