Skip to content

Commit a8f09df

Browse files
committed
update expires at
1 parent af27abb commit a8f09df

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

src/api/functions/auditLog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import {
55
} from "@aws-sdk/client-dynamodb";
66
import { marshall } from "@aws-sdk/util-dynamodb";
77
import { genericConfig } from "common/config.js";
8+
import { AUDIT_LOG_RETENTION_DAYS } from "common/constants.js";
89
import { AuditLogEntry } from "common/types/logs.js";
910

1011
type AuditLogParams = {
1112
dynamoClient?: DynamoDBClient;
1213
entry: AuditLogEntry;
1314
};
1415

15-
const RETENTION_DAYS = 365;
16-
1716
function buildMarshalledAuditLogItem(entry: AuditLogEntry) {
1817
const baseNow = Date.now();
1918
const timestamp = Math.floor(baseNow / 1000);
2019
const expireAt =
21-
timestamp + Math.floor((RETENTION_DAYS * 24 * 60 * 60 * 1000) / 1000);
20+
timestamp +
21+
Math.floor((AUDIT_LOG_RETENTION_DAYS * 24 * 60 * 60 * 1000) / 1000);
2222

2323
return marshall(
2424
{

src/api/routes/roomRequests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getDefaultFilteringQuerystring,
3737
nonEmptyCommaSeparatedStringSchema,
3838
} from "common/utils.js";
39+
import { ROOM_RESERVATION_RETENTION_DAYS } from "common/constants.js";
3940

4041
const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
4142
await fastify.register(rateLimiter, {
@@ -104,6 +105,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
104105
semesterId,
105106
"createdAt#status": `${createdAt}#${request.body.status}`,
106107
createdBy: request.username,
108+
expiresAt:
109+
Math.floor(Date.now() / 1000) +
110+
86400 * ROOM_RESERVATION_RETENTION_DAYS,
107111
...request.body,
108112
},
109113
{ removeUndefinedValues: true },
@@ -315,6 +319,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
315319
userId: request.username,
316320
"userId#requestId": `${request.username}#${requestId}`,
317321
semesterId: request.body.semester,
322+
expiresAt:
323+
Math.floor(Date.now() / 1000) +
324+
86400 * ROOM_RESERVATION_RETENTION_DAYS,
318325
};
319326
const logStatement = buildAuditLogTransactPut({
320327
entry: {
@@ -344,6 +351,9 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
344351
"createdAt#status": `${createdAt}#${RoomRequestStatus.CREATED}`,
345352
createdBy: request.username,
346353
status: RoomRequestStatus.CREATED,
354+
expiresAt:
355+
Math.floor(Date.now() / 1000) +
356+
86400 * ROOM_RESERVATION_RETENTION_DAYS,
347357
notes: "This request was created by the user.",
348358
}),
349359
},

src/api/routes/stripe.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { AvailableSQSFunctions, SQSPayload } from "common/types/sqsMessage.js";
4545
import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
4646
import * as z from "zod/v4";
4747
import { getAllUserEmails } from "common/utils.js";
48+
import { STRIPE_LINK_RETENTION_DAYS } from "common/constants.js";
4849

4950
const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
5051
await fastify.register(rawbody, {
@@ -250,7 +251,8 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
250251
},
251252
});
252253
// expire deleted links at 90 days
253-
const expiresAt = Math.floor(Date.now() / 1000) + 86400 * 90;
254+
const expiresAt =
255+
Math.floor(Date.now() / 1000) + 86400 * STRIPE_LINK_RETENTION_DAYS;
254256
const dynamoCommand = new TransactWriteItemsCommand({
255257
TransactItems: [
256258
...(logStatement ? [logStatement] : []),
@@ -669,11 +671,18 @@ Please contact Officer Board with any questions.`,
669671
userId: { S: unmarshalledEntry.userId },
670672
linkId: { S: paymentLinkId },
671673
},
672-
UpdateExpression: "SET active = :new_val",
674+
UpdateExpression:
675+
"SET active = :new_val, expiresAt = :ttl",
673676
ConditionExpression: "active = :old_val",
674677
ExpressionAttributeValues: {
675678
":new_val": { BOOL: false },
676679
":old_val": { BOOL: true },
680+
":ttl": {
681+
N: (
682+
Math.floor(Date.now() / 1000) +
683+
86400 * STRIPE_LINK_RETENTION_DAYS
684+
).toString(),
685+
},
677686
},
678687
},
679688
},

src/common/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const STRIPE_LINK_RETENTION_DAYS = 90; // this number of days after the link is deactivated.
2+
export const AUDIT_LOG_RETENTION_DAYS = 365;
3+
export const ROOM_RESERVATION_RETENTION_DAYS = 730;

src/ui/pages/stripe/CurrentLinks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { notifications } from "@mantine/notifications";
1818
import { useAuth } from "@ui/components/AuthContext";
1919
import pluralize from "pluralize";
2020
import dayjs from "dayjs";
21+
import { STRIPE_LINK_RETENTION_DAYS } from "@common/constants";
2122

2223
const HumanFriendlyDate = ({ date }: { date: string | Date }) => {
2324
return <Text size="sm">{dayjs(date).format("MMMM D, YYYY")}</Text>;
@@ -147,8 +148,7 @@ export const StripeCurrentLinksPanel: React.FC<
147148
if (result.success > 0) {
148149
notifications.show({
149150
title: `Deactivated ${pluralize("link", result.success, true)}!`,
150-
message:
151-
"Links will be permanently removed from this page after 90 days.",
151+
message: `Links will be permanently removed from this page after ${STRIPE_LINK_RETENTION_DAYS} days.`,
152152
color: "green",
153153
});
154154
}

terraform/modules/dynamo/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ resource "aws_dynamodb_table" "room_requests" {
8080
hash_key = "requestId"
8181
projection_type = "ALL"
8282
}
83+
ttl {
84+
attribute_name = "expiresAt"
85+
enabled = true
86+
}
8387
}
8488

8589

@@ -110,6 +114,10 @@ resource "aws_dynamodb_table" "room_requests_status" {
110114
range_key = "requestId"
111115
projection_type = "ALL"
112116
}
117+
ttl {
118+
attribute_name = "expiresAt"
119+
enabled = true
120+
}
113121
}
114122

115123

0 commit comments

Comments
 (0)