Skip to content

Commit

Permalink
chore: apply all small changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
joseglego committed Nov 5, 2024
1 parent 21804c9 commit 66d2d1e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/schema/purchaseOrder/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ export const syncPurchaseOrderPaymentStatus = async ({
username: purchaseOrder.user.username,
},
transferMessage: transferAttempt.transferMessage,
expirationDate,
userTicket: userTicket,
},
logger,
Expand Down
2 changes: 1 addition & 1 deletion src/schema/userTickets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
5 changes: 4 additions & 1 deletion src/schema/userTicketsTransfers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type SendStartTransferTicketSuccesfulEmailsArgs = {
username: string | null;
};
transferMessage?: string | null;
expirationDate?: Date;
userTicket: {
publicId: string;
ticketTemplate: {
Expand Down Expand Up @@ -113,6 +114,7 @@ type SendAcceptTransferTicketSuccesfulEmailArgs = {
username: string | null;
};
transferMessage?: string | null;
expirationDate?: Date;
userTicket: {
publicId: string;
ticketTemplate: {
Expand Down Expand Up @@ -154,7 +156,7 @@ export const sendAcceptTransferTicketSuccesfulEmail = async ({
);
}

const communityInfo = eventInfo.eventsToCommunities[0].community;
const communityInfo = eventInfo.eventsToCommunities?.[0].community;

if (!communityInfo) {
throw applicationError(
Expand All @@ -170,6 +172,7 @@ export const sendAcceptTransferTicketSuccesfulEmail = async ({
recipientUser: userTicketTransfer.recipientUser,
senderUser: userTicketTransfer.senderUser,
userTicket: userTicketTransfer.userTicket,
expirationDate: userTicketTransfer.expirationDate,
transferMessage: "",
},
communityInfo: {
Expand Down
16 changes: 11 additions & 5 deletions src/schema/userTicketsTransfers/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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)
Expand All @@ -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: {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion workers/transactional_email_service/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export default class EmailService extends WorkerEntrypoint<ENV> {
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;
Expand Down
1 change: 1 addition & 0 deletions workers/transactional_email_service/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface UserTicketTransferInfo {
username: string | null;
},
transferMessage?: string | null;
expirationDate?: Date;
userTicket: {
publicId: string;
ticketTemplate: {
Expand Down

0 comments on commit 66d2d1e

Please sign in to comment.