@@ -27,7 +27,7 @@ import { genericConfig, notificationRecipients } from "common/config.js";
2727import { marshall , unmarshall } from "@aws-sdk/util-dynamodb" ;
2828import { AvailableSQSFunctions , SQSPayload } from "common/types/sqsMessage.js" ;
2929import { SendMessageCommand , SQSClient } from "@aws-sdk/client-sqs" ;
30- import { withTags } from "api/components/index.js" ;
30+ import { withRoles , withTags } from "api/components/index.js" ;
3131import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi" ;
3232import { z } from "zod" ;
3333
@@ -37,29 +37,27 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
3737 duration : 30 ,
3838 rateLimitIdentifier : "roomRequests" ,
3939 } ) ;
40- fastify . post < {
41- Body : RoomRequestStatusUpdatePostBody ;
42- Params : { requestId : string ; semesterId : string } ;
43- } > (
40+ fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . post (
4441 "/:semesterId/:requestId/status" ,
4542 {
46- schema : withTags ( [ "Room Requests" ] , {
47- summary : "Create status update for a room request." ,
48- params : z . object ( {
49- requestId : z . string ( ) . min ( 1 ) . openapi ( {
50- description : "Room request ID." ,
51- example : "6667e095-8b04-4877-b361-f636f459ba42" ,
52- } ) ,
53- semesterId : z . string ( ) . min ( 1 ) . openapi ( {
54- description : "Short semester slug for a given semester." ,
55- example : "sp25" ,
43+ schema : withRoles (
44+ [ AppRoles . ROOM_REQUEST_UPDATE ] ,
45+ withTags ( [ "Room Requests" ] , {
46+ summary : "Create status update for a room request." ,
47+ params : z . object ( {
48+ requestId : z . string ( ) . min ( 1 ) . openapi ( {
49+ description : "Room request ID." ,
50+ example : "6667e095-8b04-4877-b361-f636f459ba42" ,
51+ } ) ,
52+ semesterId : z . string ( ) . min ( 1 ) . openapi ( {
53+ description : "Short semester slug for a given semester." ,
54+ example : "sp25" ,
55+ } ) ,
5656 } ) ,
57+ body : roomRequestStatusUpdateRequest ,
5758 } ) ,
58- body : roomRequestStatusUpdateRequest ,
59- } ) ,
60- onRequest : async ( request , reply ) => {
61- await fastify . authorize ( request , reply , [ AppRoles . ROOM_REQUEST_UPDATE ] ) ;
62- } ,
59+ ) ,
60+ onRequest : fastify . authorizeFromSchema ,
6361 } ,
6462 async ( request , reply ) => {
6563 if ( ! request . username ) {
@@ -154,18 +152,19 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
154152 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . get (
155153 "/:semesterId" ,
156154 {
157- schema : withTags ( [ "Room Requests" ] , {
158- summary : "Get room requests for a specific semester." ,
159- params : z . object ( {
160- semesterId : z . string ( ) . min ( 1 ) . openapi ( {
161- description : "Short semester slug for a given semester." ,
162- example : "sp25" ,
155+ schema : withRoles (
156+ [ AppRoles . ROOM_REQUEST_CREATE ] ,
157+ withTags ( [ "Room Requests" ] , {
158+ summary : "Get room requests for a specific semester." ,
159+ params : z . object ( {
160+ semesterId : z . string ( ) . min ( 1 ) . openapi ( {
161+ description : "Short semester slug for a given semester." ,
162+ example : "sp25" ,
163+ } ) ,
163164 } ) ,
164165 } ) ,
165- } ) ,
166- onRequest : async ( request , reply ) => {
167- await fastify . authorize ( request , reply , [ AppRoles . ROOM_REQUEST_CREATE ] ) ;
168- } ,
166+ ) ,
167+ onRequest : fastify . authorizeFromSchema ,
169168 } ,
170169 async ( request , reply ) => {
171170 const semesterId = request . params . semesterId ;
@@ -252,13 +251,14 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
252251 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . post (
253252 "" ,
254253 {
255- schema : withTags ( [ "Room Requests" ] , {
256- summary : "Create a room request." ,
257- body : roomRequestSchema ,
258- } ) ,
259- onRequest : async ( request , reply ) => {
260- await fastify . authorize ( request , reply , [ AppRoles . ROOM_REQUEST_CREATE ] ) ;
261- } ,
254+ schema : withRoles (
255+ [ AppRoles . ROOM_REQUEST_CREATE ] ,
256+ withTags ( [ "Room Requests" ] , {
257+ summary : "Create a room request." ,
258+ body : roomRequestSchema ,
259+ } ) ,
260+ ) ,
261+ onRequest : fastify . authorizeFromSchema ,
262262 } ,
263263 async ( request , reply ) => {
264264 const requestId = request . id ;
@@ -350,22 +350,23 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
350350 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . get (
351351 "/:semesterId/:requestId" ,
352352 {
353- schema : withTags ( [ "Room Requests" ] , {
354- summary : "Get specific room request data." ,
355- params : z . object ( {
356- requestId : z . string ( ) . min ( 1 ) . openapi ( {
357- description : "Room request ID." ,
358- example : "6667e095-8b04-4877-b361-f636f459ba42" ,
359- } ) ,
360- semesterId : z . string ( ) . min ( 1 ) . openapi ( {
361- description : "Short semester slug for a given semester." ,
362- example : "sp25" ,
353+ schema : withRoles (
354+ [ AppRoles . ROOM_REQUEST_CREATE ] ,
355+ withTags ( [ "Room Requests" ] , {
356+ summary : "Get specific room request data." ,
357+ params : z . object ( {
358+ requestId : z . string ( ) . min ( 1 ) . openapi ( {
359+ description : "Room request ID." ,
360+ example : "6667e095-8b04-4877-b361-f636f459ba42" ,
361+ } ) ,
362+ semesterId : z . string ( ) . min ( 1 ) . openapi ( {
363+ description : "Short semester slug for a given semester." ,
364+ example : "sp25" ,
365+ } ) ,
363366 } ) ,
364367 } ) ,
365- } ) ,
366- onRequest : async ( request , reply ) => {
367- await fastify . authorize ( request , reply , [ AppRoles . ROOM_REQUEST_CREATE ] ) ;
368- } ,
368+ ) ,
369+ onRequest : fastify . authorizeFromSchema ,
369370 } ,
370371 async ( request , reply ) => {
371372 const requestId = request . params . requestId ;
0 commit comments