11import { FastifyError , FastifyPluginAsync } from "fastify" ;
22import {
3- ACMOrganization ,
4- AllOrganizationList ,
5- OrganizationShortIdentifierMapping ,
3+ AllOrganizationNameList ,
4+ getOrgByName ,
5+ Organizations ,
66} from "@acm-uiuc/js-shared" ;
77import rateLimiter from "api/plugins/rateLimiter.js" ;
88import { withRoles , withTags } from "api/components/index.js" ;
@@ -142,7 +142,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
142142 isAuthenticated = false ;
143143 }
144144 }
145- const promises = AllOrganizationList . map ( ( x ) =>
145+ const promises = AllOrganizationNameList . map ( ( x ) =>
146146 getOrgInfo ( {
147147 id : x ,
148148 dynamoClient : fastify . dynamoClient ,
@@ -161,7 +161,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
161161 leadsEntraGroupId : undefined ,
162162 } ) ) ;
163163 }
164- const unknownIds = AllOrganizationList . filter (
164+ const unknownIds = AllOrganizationNameList . filter (
165165 ( x ) => ! successIds . includes ( x ) ,
166166 ) . map ( ( x ) => ( { id : x } ) ) ;
167167 return reply . send ( [ ...successOnly , ...unknownIds ] ) ;
@@ -185,7 +185,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
185185 "Get information about a specific ACM @ UIUC sub-organization." ,
186186 params : z . object ( {
187187 orgId : z
188- . enum ( AllOrganizationList )
188+ . enum ( AllOrganizationNameList )
189189 . meta ( { description : "ACM @ UIUC organization to query." } ) ,
190190 } ) ,
191191 response : {
@@ -236,7 +236,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
236236 summary : "Set metadata for an ACM @ UIUC sub-organization." ,
237237 params : z . object ( {
238238 orgId : z
239- . enum ( AllOrganizationList )
239+ . enum ( AllOrganizationNameList )
240240 . meta ( { description : "ACM @ UIUC organization to modify." } ) ,
241241 } ) ,
242242 body : setOrganizationMetaBody ,
@@ -325,7 +325,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
325325 summary : "Set leads for an ACM @ UIUC sub-organization." ,
326326 params : z . object ( {
327327 orgId : z
328- . enum ( AllOrganizationList )
328+ . enum ( AllOrganizationNameList )
329329 . meta ( { description : "ACM @ UIUC organization to modify." } ) ,
330330 } ) ,
331331 body : patchOrganizationLeadsBody ,
@@ -424,7 +424,13 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
424424
425425 const shouldCreateNewEntraGroup = ! entraGroupId ;
426426 const grpDisplayName = `${ request . params . orgId } Admin` ;
427- const grpShortName = `${ OrganizationShortIdentifierMapping [ request . params . orgId as keyof typeof OrganizationShortIdentifierMapping ] } -adm` ;
427+ const orgInfo = getOrgByName ( request . params . orgId ) ;
428+ if ( ! orgInfo ) {
429+ throw new InternalServerError ( {
430+ message : `Organization ${ request . params . orgId } could not be resolved.` ,
431+ } ) ;
432+ }
433+ const grpShortName = `${ orgInfo ?. shortcode } -adm` ;
428434
429435 // Create Entra group if needed
430436 if ( shouldCreateNewEntraGroup ) {
0 commit comments