@@ -30,6 +30,11 @@ import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi";
30
30
import { z } from "zod" ;
31
31
import { buildAuditLogTransactPut } from "api/functions/auditLog.js" ;
32
32
import { Modules } from "common/modules.js" ;
33
+ import {
34
+ generateProjectionParams ,
35
+ getDefaultFilteringQuerystring ,
36
+ nonEmptyCommaSeparatedStringSchema ,
37
+ } from "common/utils.js" ;
33
38
34
39
const roomRequestRoutes : FastifyPluginAsync = async ( fastify , _options ) => {
35
40
await fastify . register ( rateLimiter , {
@@ -182,12 +187,19 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
182
187
example : "sp25" ,
183
188
} ) ,
184
189
} ) ,
190
+ querystring : z . object (
191
+ getDefaultFilteringQuerystring ( {
192
+ defaultSelect : [ "requestId" , "title" ] ,
193
+ } ) ,
194
+ ) ,
185
195
} ) ,
186
196
) ,
187
197
onRequest : fastify . authorizeFromSchema ,
188
198
} ,
189
199
async ( request , reply ) => {
190
200
const semesterId = request . params . semesterId ;
201
+ const { ProjectionExpression, ExpressionAttributeNames } =
202
+ generateProjectionParams ( { userFields : request . query . select } ) ;
191
203
if ( ! request . username ) {
192
204
throw new InternalServerError ( {
193
205
message : "Could not retrieve username." ,
@@ -198,6 +210,8 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
198
210
command = new QueryCommand ( {
199
211
TableName : genericConfig . RoomRequestsTableName ,
200
212
KeyConditionExpression : "semesterId = :semesterValue" ,
213
+ ProjectionExpression,
214
+ ExpressionAttributeNames,
201
215
ExpressionAttributeValues : {
202
216
":semesterValue" : { S : semesterId } ,
203
217
} ,
@@ -209,8 +223,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
209
223
"semesterId = :semesterValue AND begins_with(#sortKey, :username)" ,
210
224
ExpressionAttributeNames : {
211
225
"#sortKey" : "userId#requestId" ,
226
+ ...ExpressionAttributeNames ,
212
227
} ,
213
- ProjectionExpression : "requestId, host, title, semester" ,
228
+ ProjectionExpression,
214
229
ExpressionAttributeValues : {
215
230
":semesterValue" : { S : semesterId } ,
216
231
":username" : { S : request . username } ,
@@ -224,6 +239,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
224
239
} ) ;
225
240
}
226
241
const items = response . Items . map ( ( x ) => {
242
+ if ( ! request . query . select . includes ( "status" ) ) {
243
+ return unmarshall ( x ) ;
244
+ }
227
245
const item = unmarshall ( x ) as {
228
246
host : string ;
229
247
title : string ;
@@ -403,20 +421,29 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
403
421
example : "sp25" ,
404
422
} ) ,
405
423
} ) ,
424
+ querystring : z . object (
425
+ getDefaultFilteringQuerystring ( {
426
+ defaultSelect : [ "requestId" , "title" ] ,
427
+ } ) ,
428
+ ) ,
406
429
} ) ,
407
430
) ,
408
431
onRequest : fastify . authorizeFromSchema ,
409
432
} ,
410
433
async ( request , reply ) => {
411
434
const requestId = request . params . requestId ;
412
435
const semesterId = request . params . semesterId ;
436
+ const { ProjectionExpression, ExpressionAttributeNames } =
437
+ generateProjectionParams ( { userFields : request . query . select } ) ;
413
438
let command ;
414
439
if ( request . userRoles ?. has ( AppRoles . BYPASS_OBJECT_LEVEL_AUTH ) ) {
415
440
command = new QueryCommand ( {
416
441
TableName : genericConfig . RoomRequestsTableName ,
417
442
IndexName : "RequestIdIndex" ,
418
443
KeyConditionExpression : "requestId = :requestId" ,
419
444
FilterExpression : "semesterId = :semesterId" ,
445
+ ProjectionExpression,
446
+ ExpressionAttributeNames,
420
447
ExpressionAttributeValues : {
421
448
":requestId" : { S : requestId } ,
422
449
":semesterId" : { S : semesterId } ,
@@ -426,6 +453,7 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
426
453
} else {
427
454
command = new QueryCommand ( {
428
455
TableName : genericConfig . RoomRequestsTableName ,
456
+ ProjectionExpression,
429
457
KeyConditionExpression :
430
458
"semesterId = :semesterId AND #userIdRequestId = :userRequestId" ,
431
459
ExpressionAttributeValues : {
@@ -434,6 +462,7 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
434
462
} ,
435
463
ExpressionAttributeNames : {
436
464
"#userIdRequestId" : "userId#requestId" ,
465
+ ...ExpressionAttributeNames ,
437
466
} ,
438
467
Limit : 1 ,
439
468
} ) ;
0 commit comments