From 66d2d1e147546d8f5d832f1240c92602bf14d772 Mon Sep 17 00:00:00 2001 From: Jose Lezama Date: Mon, 4 Nov 2024 22:11:33 -0300 Subject: [PATCH] chore: apply all small changes from review --- src/schema/purchaseOrder/actions.tsx | 1 + src/schema/userTickets/constants.ts | 2 +- src/schema/userTicketsTransfers/actions.ts | 5 ++++- src/schema/userTicketsTransfers/mutations.ts | 16 +++++++++++----- workers/transactional_email_service/index.tsx | 2 +- workers/transactional_email_service/types.ts | 1 + 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/schema/purchaseOrder/actions.tsx b/src/schema/purchaseOrder/actions.tsx index 5835b4af..eb7a712b 100644 --- a/src/schema/purchaseOrder/actions.tsx +++ b/src/schema/purchaseOrder/actions.tsx @@ -1091,6 +1091,7 @@ export const syncPurchaseOrderPaymentStatus = async ({ username: purchaseOrder.user.username, }, transferMessage: transferAttempt.transferMessage, + expirationDate, userTicket: userTicket, }, logger, diff --git a/src/schema/userTickets/constants.ts b/src/schema/userTickets/constants.ts index bed62964..84595d2e 100644 --- a/src/schema/userTickets/constants.ts +++ b/src/schema/userTickets/constants.ts @@ -23,7 +23,7 @@ export const REDEEMABLE_USER_TICKET_APPROVAL_STATUSES: UserTicketApprovalStatus[ /** * This statuses are taken into account - * when counting the number of available stick + * when counting the number of available stock */ export const RESERVED_USER_TICKET_APPROVAL_STATUSES: UserTicketApprovalStatus[] = [...ACCESSIBLE_USER_TICKET_APPROVAL_STATUSES, "pending"]; diff --git a/src/schema/userTicketsTransfers/actions.ts b/src/schema/userTicketsTransfers/actions.ts index 7fad024b..cf90273f 100644 --- a/src/schema/userTicketsTransfers/actions.ts +++ b/src/schema/userTicketsTransfers/actions.ts @@ -18,6 +18,7 @@ type SendStartTransferTicketSuccesfulEmailsArgs = { username: string | null; }; transferMessage?: string | null; + expirationDate?: Date; userTicket: { publicId: string; ticketTemplate: { @@ -113,6 +114,7 @@ type SendAcceptTransferTicketSuccesfulEmailArgs = { username: string | null; }; transferMessage?: string | null; + expirationDate?: Date; userTicket: { publicId: string; ticketTemplate: { @@ -154,7 +156,7 @@ export const sendAcceptTransferTicketSuccesfulEmail = async ({ ); } - const communityInfo = eventInfo.eventsToCommunities[0].community; + const communityInfo = eventInfo.eventsToCommunities?.[0].community; if (!communityInfo) { throw applicationError( @@ -170,6 +172,7 @@ export const sendAcceptTransferTicketSuccesfulEmail = async ({ recipientUser: userTicketTransfer.recipientUser, senderUser: userTicketTransfer.senderUser, userTicket: userTicketTransfer.userTicket, + expirationDate: userTicketTransfer.expirationDate, transferMessage: "", }, communityInfo: { diff --git a/src/schema/userTicketsTransfers/mutations.ts b/src/schema/userTicketsTransfers/mutations.ts index 9fb310b5..89e579e5 100644 --- a/src/schema/userTicketsTransfers/mutations.ts +++ b/src/schema/userTicketsTransfers/mutations.ts @@ -239,11 +239,11 @@ builder.mutationField("acceptTransferredTicket", (t) => ); if (!ticketTransfer) { - throw new GraphQLError("Could not find ticket to accept"); + throw new GraphQLError("Could not find Ticket Transfer to accept"); } if (ticketTransfer.status !== UserTicketTransferStatus.Pending) { - throw new GraphQLError("Ticket is not transferable"); + throw new GraphQLError("Ticket Transfer is not processable"); } if (ticketTransfer.expirationDate <= new Date()) { @@ -253,7 +253,7 @@ builder.mutationField("acceptTransferredTicket", (t) => }) .where(eq(userTicketTransfersSchema.id, ticketTransfer.id)); - throw new GraphQLError("Transfer attempt has expired"); + throw new GraphQLError("Ticket Transfer has expired"); } await DB.update(userTicketsSchema) @@ -273,7 +273,7 @@ builder.mutationField("acceptTransferredTicket", (t) => .returning() .then((t) => t?.[0]); - const userTicket = await DB.query.userTicketsSchema.findMany({ + const userTickets = await DB.query.userTicketsSchema.findMany({ where: (ut, { eq }) => eq(ut.id, ticketTransfer.userTicketId), with: { ticketTemplate: { @@ -299,10 +299,16 @@ builder.mutationField("acceptTransferredTicket", (t) => }, }); + if (!userTickets.length) { + throw new GraphQLError( + "Could not find associated Ticket to Ticket Transfer", + ); + } + await sendAcceptTransferTicketSuccesfulEmail({ userTicketTransfer: { ...ticketTransfer, - userTicket: userTicket[0], + userTicket: userTickets[0], }, logger, transactionalEmailService: RPC_SERVICE_EMAIL, diff --git a/workers/transactional_email_service/index.tsx b/workers/transactional_email_service/index.tsx index f92a5bd8..5562ef61 100644 --- a/workers/transactional_email_service/index.tsx +++ b/workers/transactional_email_service/index.tsx @@ -405,7 +405,7 @@ export default class EmailService extends WorkerEntrypoint { recipientEmail: userTicketTransfer.recipientUser.email, senderEmail: userTicketTransfer.senderUser.email }); - const expirationDate = add(new Date(), { weeks: 1 }); + const expirationDate = userTicketTransfer.expirationDate ?? add(new Date(), { weeks: 1 }); if (communityInfo.name === "9punto5") { const userTicket = userTicketTransfer.userTicket; diff --git a/workers/transactional_email_service/types.ts b/workers/transactional_email_service/types.ts index 67c42886..883fa9a3 100644 --- a/workers/transactional_email_service/types.ts +++ b/workers/transactional_email_service/types.ts @@ -30,6 +30,7 @@ export interface UserTicketTransferInfo { username: string | null; }, transferMessage?: string | null; + expirationDate?: Date; userTicket: { publicId: string; ticketTemplate: {