@@ -26,6 +26,7 @@ import { createAuditLogEntry } from "api/functions/auditLog.js";
2626import { Modules } from "common/modules.js" ;
2727import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi" ;
2828import { withRoles , withTags } from "api/components/index.js" ;
29+ import { FULFILLED_PURCHASES_RETENTION_DAYS } from "common/constants.js" ;
2930
3031const 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" ,
0 commit comments