Skip to content

Commit c654d87

Browse files
committed
expire claimed tickets
1 parent 2e8af14 commit c654d87

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/api/routes/tickets.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { createAuditLogEntry } from "api/functions/auditLog.js";
2626
import { Modules } from "common/modules.js";
2727
import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi";
2828
import { withRoles, withTags } from "api/components/index.js";
29+
import { FULFILLED_PURCHASES_RETENTION_DAYS } from "common/constants.js";
2930

3031
const postMerchSchema = z.object({
3132
type: z.literal("merch"),
@@ -355,6 +356,9 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
355356
message: "Could not find username.",
356357
});
357358
}
359+
const expiresAt =
360+
Math.floor(Date.now() / 1000) +
361+
86400 * FULFILLED_PURCHASES_RETENTION_DAYS;
358362
switch (request.body.type) {
359363
case "merch":
360364
ticketId = request.body.stripePi;
@@ -363,7 +367,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
363367
Key: {
364368
stripe_pi: { S: ticketId },
365369
},
366-
UpdateExpression: "SET fulfilled = :true_val",
370+
UpdateExpression: "SET fulfilled = :true_val, expiresAt = :ttl",
367371
ConditionExpression:
368372
"#email = :email_val AND (attribute_not_exists(fulfilled) OR fulfilled = :false_val) AND (attribute_not_exists(refunded) OR refunded = :false_val)",
369373
ExpressionAttributeNames: {
@@ -373,6 +377,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
373377
":true_val": { BOOL: true },
374378
":false_val": { BOOL: false },
375379
":email_val": { S: request.body.email },
380+
":ttl": { N: expiresAt.toString() },
376381
},
377382
ReturnValuesOnConditionCheckFailure: "ALL_OLD",
378383
ReturnValues: "ALL_OLD",
@@ -385,7 +390,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
385390
Key: {
386391
ticket_id: { S: ticketId },
387392
},
388-
UpdateExpression: "SET #used = :trueValue",
393+
UpdateExpression: "SET #used = :trueValue, expiresAt = :ttl",
389394
ConditionExpression:
390395
"(attribute_not_exists(#used) OR #used = :falseValue) AND (attribute_not_exists(refunded) OR refunded = :falseValue)",
391396
ExpressionAttributeNames: {
@@ -394,6 +399,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
394399
ExpressionAttributeValues: {
395400
":trueValue": { BOOL: true },
396401
":falseValue": { BOOL: false },
402+
":ttl": { N: expiresAt.toString() },
397403
},
398404
ReturnValuesOnConditionCheckFailure: "ALL_OLD",
399405
ReturnValues: "ALL_OLD",

src/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const STRIPE_LINK_RETENTION_DAYS = 90; // this number of days after the link is deactivated.
22
export const AUDIT_LOG_RETENTION_DAYS = 365;
33
export const ROOM_RESERVATION_RETENTION_DAYS = 730;
4+
export const FULFILLED_PURCHASES_RETENTION_DAYS = 365; // ticketing/merch: after the purchase is marked as fulfilled.

0 commit comments

Comments
 (0)