Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/api/routes/roomRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
getAllUserEmails,
getDefaultFilteringQuerystring,
} from "common/utils.js";
import { ROOM_RESERVATION_RETENTION_DAYS } from "common/constants.js";
import {
ROOM_RESERVATION_RETENTION_DAYS,
UPLOAD_GRACE_PERIOD_MS,
} from "common/constants.js";
import { createPresignedGet, createPresignedPut } from "api/functions/s3.js";
import { HeadObjectCommand, NotFound, S3Client } from "@aws-sdk/client-s3";

Expand Down Expand Up @@ -680,22 +683,29 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
);
} catch (error) {
if (error instanceof NotFound) {
// Key doesn't exist in S3, delete the attribute from DynamoDB
await fastify.dynamoClient.send(
new UpdateItemCommand({
TableName: genericConfig.RoomRequestsStatusTableName,
Key: {
requestId: { S: request.params.requestId },
"createdAt#status": {
S: `${request.params.createdAt}#${request.params.status}`,
// Check if grace period has passed since creation
const createdAt = new Date(request.params.createdAt);
const now = new Date();
const timeSinceCreation = now.getTime() - createdAt.getTime();

if (timeSinceCreation >= UPLOAD_GRACE_PERIOD_MS) {
// Grace period has passed, delete the attribute from DynamoDB
await fastify.dynamoClient.send(
new UpdateItemCommand({
TableName: genericConfig.RoomRequestsStatusTableName,
Key: {
requestId: { S: request.params.requestId },
"createdAt#status": {
S: `${request.params.createdAt}#${request.params.status}`,
},
},
},
UpdateExpression: "REMOVE #attachmentS3key",
ExpressionAttributeNames: {
"#attachmentS3key": "attachmentS3key",
},
}),
);
UpdateExpression: "REMOVE #attachmentS3key",
ExpressionAttributeNames: {
"#attachmentS3key": "attachmentS3key",
},
}),
);
}

throw new NotFoundError({
endpointName: request.url,
Expand Down
1 change: 1 addition & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export const AUDIT_LOG_RETENTION_DAYS = 365;
export const ROOM_RESERVATION_RETENTION_DAYS = 1460;
export const FULFILLED_PURCHASES_RETENTION_DAYS = 1460; // ticketing/merch: after the purchase is marked as fulfilled.
export const EVENTS_EXPIRY_AFTER_LAST_OCCURRENCE_DAYS = 1460; // hold events for 4 years after last occurrence
export const UPLOAD_GRACE_PERIOD_MS = 30 * 60 * 1000; // 30 minutes
// we keep data longer for historical analytics purposes in S3 as needed
Loading