@@ -30,6 +30,11 @@ import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi";
3030import { z } from "zod" ;
3131import { buildAuditLogTransactPut } from "api/functions/auditLog.js" ;
3232import { Modules } from "common/modules.js" ;
33+ import {
34+ generateProjectionParams ,
35+ getDefaultFilteringQuerystring ,
36+ nonEmptyCommaSeparatedStringSchema ,
37+ } from "common/utils.js" ;
3338
3439const roomRequestRoutes : FastifyPluginAsync = async ( fastify , _options ) => {
3540 await fastify . register ( rateLimiter , {
@@ -182,12 +187,19 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
182187 example : "sp25" ,
183188 } ) ,
184189 } ) ,
190+ querystring : z . object (
191+ getDefaultFilteringQuerystring ( {
192+ defaultSelect : [ "requestId" , "title" ] ,
193+ } ) ,
194+ ) ,
185195 } ) ,
186196 ) ,
187197 onRequest : fastify . authorizeFromSchema ,
188198 } ,
189199 async ( request , reply ) => {
190200 const semesterId = request . params . semesterId ;
201+ const { ProjectionExpression, ExpressionAttributeNames } =
202+ generateProjectionParams ( { userFields : request . query . select } ) ;
191203 if ( ! request . username ) {
192204 throw new InternalServerError ( {
193205 message : "Could not retrieve username." ,
@@ -198,6 +210,8 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
198210 command = new QueryCommand ( {
199211 TableName : genericConfig . RoomRequestsTableName ,
200212 KeyConditionExpression : "semesterId = :semesterValue" ,
213+ ProjectionExpression,
214+ ExpressionAttributeNames,
201215 ExpressionAttributeValues : {
202216 ":semesterValue" : { S : semesterId } ,
203217 } ,
@@ -209,8 +223,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
209223 "semesterId = :semesterValue AND begins_with(#sortKey, :username)" ,
210224 ExpressionAttributeNames : {
211225 "#sortKey" : "userId#requestId" ,
226+ ...ExpressionAttributeNames ,
212227 } ,
213- ProjectionExpression : "requestId, host, title, semester" ,
228+ ProjectionExpression,
214229 ExpressionAttributeValues : {
215230 ":semesterValue" : { S : semesterId } ,
216231 ":username" : { S : request . username } ,
@@ -224,6 +239,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
224239 } ) ;
225240 }
226241 const items = response . Items . map ( ( x ) => {
242+ if ( ! request . query . select . includes ( "status" ) ) {
243+ return unmarshall ( x ) ;
244+ }
227245 const item = unmarshall ( x ) as {
228246 host : string ;
229247 title : string ;
@@ -403,20 +421,29 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
403421 example : "sp25" ,
404422 } ) ,
405423 } ) ,
424+ querystring : z . object (
425+ getDefaultFilteringQuerystring ( {
426+ defaultSelect : [ "requestId" , "title" ] ,
427+ } ) ,
428+ ) ,
406429 } ) ,
407430 ) ,
408431 onRequest : fastify . authorizeFromSchema ,
409432 } ,
410433 async ( request , reply ) => {
411434 const requestId = request . params . requestId ;
412435 const semesterId = request . params . semesterId ;
436+ const { ProjectionExpression, ExpressionAttributeNames } =
437+ generateProjectionParams ( { userFields : request . query . select } ) ;
413438 let command ;
414439 if ( request . userRoles ?. has ( AppRoles . BYPASS_OBJECT_LEVEL_AUTH ) ) {
415440 command = new QueryCommand ( {
416441 TableName : genericConfig . RoomRequestsTableName ,
417442 IndexName : "RequestIdIndex" ,
418443 KeyConditionExpression : "requestId = :requestId" ,
419444 FilterExpression : "semesterId = :semesterId" ,
445+ ProjectionExpression,
446+ ExpressionAttributeNames,
420447 ExpressionAttributeValues : {
421448 ":requestId" : { S : requestId } ,
422449 ":semesterId" : { S : semesterId } ,
@@ -426,6 +453,7 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
426453 } else {
427454 command = new QueryCommand ( {
428455 TableName : genericConfig . RoomRequestsTableName ,
456+ ProjectionExpression,
429457 KeyConditionExpression :
430458 "semesterId = :semesterId AND #userIdRequestId = :userRequestId" ,
431459 ExpressionAttributeValues : {
@@ -434,6 +462,7 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
434462 } ,
435463 ExpressionAttributeNames : {
436464 "#userIdRequestId" : "userId#requestId" ,
465+ ...ExpressionAttributeNames ,
437466 } ,
438467 Limit : 1 ,
439468 } ) ;
0 commit comments