@@ -35,7 +35,10 @@ import {
3535 getAllUserEmails ,
3636 getDefaultFilteringQuerystring ,
3737} from "common/utils.js" ;
38- import { ROOM_RESERVATION_RETENTION_DAYS } from "common/constants.js" ;
38+ import {
39+ ROOM_RESERVATION_RETENTION_DAYS ,
40+ UPLOAD_GRACE_PERIOD_MS ,
41+ } from "common/constants.js" ;
3942import { createPresignedGet , createPresignedPut } from "api/functions/s3.js" ;
4043import { HeadObjectCommand , NotFound , S3Client } from "@aws-sdk/client-s3" ;
4144
@@ -680,22 +683,29 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
680683 ) ;
681684 } catch ( error ) {
682685 if ( error instanceof NotFound ) {
683- // Key doesn't exist in S3, delete the attribute from DynamoDB
684- await fastify . dynamoClient . send (
685- new UpdateItemCommand ( {
686- TableName : genericConfig . RoomRequestsStatusTableName ,
687- Key : {
688- requestId : { S : request . params . requestId } ,
689- "createdAt#status" : {
690- S : `${ request . params . createdAt } #${ request . params . status } ` ,
686+ // Check if grade period has passed since creation
687+ const createdAt = new Date ( request . params . createdAt ) ;
688+ const now = new Date ( ) ;
689+ const timeSinceCreation = now . getTime ( ) - createdAt . getTime ( ) ;
690+
691+ if ( timeSinceCreation >= UPLOAD_GRACE_PERIOD_MS ) {
692+ // Grace period has passed, delete the attribute from DynamoDB
693+ await fastify . dynamoClient . send (
694+ new UpdateItemCommand ( {
695+ TableName : genericConfig . RoomRequestsStatusTableName ,
696+ Key : {
697+ requestId : { S : request . params . requestId } ,
698+ "createdAt#status" : {
699+ S : `${ request . params . createdAt } #${ request . params . status } ` ,
700+ } ,
691701 } ,
692- } ,
693- UpdateExpression : "REMOVE #attachmentS3key" ,
694- ExpressionAttributeNames : {
695- "#attachmentS3key" : "attachmentS3key" ,
696- } ,
697- } ) ,
698- ) ;
702+ UpdateExpression : "REMOVE #attachmentS3key" ,
703+ ExpressionAttributeNames : {
704+ "#attachmentS3key" : "attachmentS3key" ,
705+ } ,
706+ } ) ,
707+ ) ;
708+ }
699709
700710 throw new NotFoundError ( {
701711 endpointName : request . url ,
0 commit comments