@@ -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,7 +210,8 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
198210 command = new QueryCommand ( {
199211 TableName : genericConfig . RoomRequestsTableName ,
200212 KeyConditionExpression : "semesterId = :semesterValue" ,
201- ProjectionExpression : "requestId, host, title, semester" ,
213+ ProjectionExpression,
214+ ExpressionAttributeNames,
202215 ExpressionAttributeValues : {
203216 ":semesterValue" : { S : semesterId } ,
204217 } ,
@@ -210,8 +223,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
210223 "semesterId = :semesterValue AND begins_with(#sortKey, :username)" ,
211224 ExpressionAttributeNames : {
212225 "#sortKey" : "userId#requestId" ,
226+ ...ExpressionAttributeNames ,
213227 } ,
214- ProjectionExpression : "requestId, host, title, semester" ,
228+ ProjectionExpression,
215229 ExpressionAttributeValues : {
216230 ":semesterValue" : { S : semesterId } ,
217231 ":username" : { S : request . username } ,
0 commit comments