Skip to content

Commit c27446a

Browse files
authored
Ensuring tickettemplate name shows up in the email (#249)
1 parent 623d06b commit c27446a

File tree

5 files changed

+86
-67
lines changed

5 files changed

+86
-67
lines changed

emails/templates/tickets/event-invitation.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import * as React from "react";
1515
import { BigFooter, TicketTemplate } from "emails/templates/helpers/tickets";
1616

1717
interface EmailProps {
18-
eventName: string;
18+
ticketName: string;
1919
userName?: string;
2020
eventLogoCloudflareImageURL: string;
2121
userEmail: string;
2222
}
2323

2424
export const EventInvitation = ({
25-
eventName,
25+
ticketName,
2626
userName,
2727
userEmail,
2828
eventLogoCloudflareImageURL,
@@ -31,7 +31,7 @@ export const EventInvitation = ({
3131
<TicketTemplate theme="light">
3232
<Container className="px-10 py-10 w-full max-w-3xl font-light">
3333
<Section className="">
34-
<Preview>Tienes una invitación a {eventName}</Preview>
34+
<Preview>Tienes una invitación a {ticketName}</Preview>
3535
<Row className="h-20 mb-14">
3636
<Column>
3737
<Img
@@ -50,7 +50,7 @@ export const EventInvitation = ({
5050
</Text>
5151

5252
<Text className="text-xl text-center mb-16 px-8 text-gray-500">
53-
{eventName}
53+
{ticketName}
5454
</Text>
5555

5656
<Text className="text-xl mb-12">
@@ -91,7 +91,8 @@ export const EventInvitation = ({
9191
};
9292

9393
EventInvitation.PreviewProps = {
94-
eventName: "El Potencial Clave de la Recuperación Aumentada (RAG) con OpenAI",
94+
ticketName:
95+
"El Potencial Clave de la Recuperación Aumentada (RAG) con OpenAI",
9596
userName: "John Doe",
9697
eventLogoCloudflareImageURL:
9798
"https://imagedelivery.net/dqFoxiedZNoncKJ9uqxz0g/6cdd148e-b931-4b7a-f983-d75d388aff00",

emails/templates/tickets/ticket-confirmation.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import * as React from "react";
1414
import { BigFooter, TicketTemplate } from "emails/templates/helpers/tickets";
1515

1616
interface EmailProps {
17-
eventName: string;
17+
ticketName: string;
1818
userTicketId: string;
1919
userName?: string;
2020
eventLogoCloudflareImageURL: string;
2121
userEmail: string;
2222
}
2323

2424
export const TicketConfirmation = ({
25-
eventName,
25+
ticketName,
2626
userTicketId,
2727
userName,
2828
userEmail,
@@ -32,7 +32,7 @@ export const TicketConfirmation = ({
3232
<TicketTemplate theme="light">
3333
<Container className="px-10 py-10 w-full max-w-3xl font-light">
3434
<Section className="">
35-
<Preview>Tu ticket para {eventName}</Preview>
35+
<Preview>Tu ticket para {ticketName}</Preview>
3636
<Row className="h-20 mb-14">
3737
<Column>
3838
<Img
@@ -51,7 +51,7 @@ export const TicketConfirmation = ({
5151
</Text>
5252

5353
<Text className="text-xl text-center mb-8 px-8 text-gray-500">
54-
{eventName}
54+
{ticketName}
5555
</Text>
5656

5757
<Container className="px-20 mb-12">
@@ -84,7 +84,8 @@ export const TicketConfirmation = ({
8484
};
8585

8686
TicketConfirmation.PreviewProps = {
87-
eventName: "El Potencial Clave de la Recuperación Aumentada (RAG) con OpenAI",
87+
ticketName:
88+
"El Potencial Clave de la Recuperación Aumentada (RAG) con OpenAI",
8889
userName: "John Doe",
8990
userTicketId: "c7fa5dc0-ffa2-4369-bac7-3aa52d7cc640",
9091
eventLogoCloudflareImageURL:

src/notifications/tickets.ts

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,40 +90,71 @@ export const sendAddedToWaitlistEmail = async ({
9090
export const sendTicketInvitationEmails = async ({
9191
DB,
9292
logger,
93-
users,
94-
ticketId,
93+
userTicketIds,
9594
RPC_SERVICE_EMAIL,
9695
}: {
9796
DB: ORM_TYPE;
9897
logger: Logger;
99-
users: USER[];
100-
ticketId: string;
98+
userTicketIds: string[];
10199
RPC_SERVICE_EMAIL: Context["RPC_SERVICE_EMAIL"];
102100
}) => {
103-
const ticketInformation = await DB.query.ticketsSchema.findFirst({
104-
where: (t, { eq }) => eq(t.id, ticketId),
101+
const userTickets = await DB.query.userTicketsSchema.findMany({
102+
where: (t, { inArray }) => inArray(t.id, userTicketIds),
105103
with: {
106-
event: true,
104+
user: true,
105+
ticketTemplate: {
106+
with: {
107+
event: true,
108+
},
109+
},
107110
},
108111
});
109112

110-
if (!ticketInformation) {
111-
throw applicationError(
112-
`Could not find ticket and event information associated to: ${ticketId}`,
113-
ServiceErrors.NOT_FOUND,
114-
logger,
115-
);
116-
}
113+
const to: {
114+
name?: string;
115+
email: string;
116+
tags: { name: string; value: string }[];
117+
userTicketId: string;
118+
ticketName: string;
119+
ticketId: string;
120+
eventId: string;
121+
}[] = [];
122+
123+
userTickets.forEach((userTicket) => {
124+
if (!userTicket.user) {
125+
return null;
126+
}
127+
128+
to.push({
129+
name: userTicket.user.name ?? undefined,
130+
email: userTicket.user.email,
131+
ticketName: userTicket.ticketTemplate.name,
132+
ticketId: userTicket.ticketTemplate.id,
133+
userTicketId: userTicket.id,
134+
eventId: userTicket.ticketTemplate.event.id,
135+
tags: [
136+
{
137+
name: "userTicket",
138+
value: userTicket.id,
139+
},
140+
{
141+
name: "ticketId",
142+
value: userTicket.ticketTemplate.id,
143+
},
144+
{
145+
name: "eventId",
146+
value: userTicket.ticketTemplate.event.id,
147+
},
148+
{
149+
name: "userId",
150+
value: userTicket.user?.id ?? "",
151+
},
152+
],
153+
});
154+
});
117155

118156
await RPC_SERVICE_EMAIL.bulkSendEventTicketInvitations({
119-
eventName: ticketInformation.event.name,
120-
ticketId: ticketInformation.id,
121-
eventId: ticketInformation.event.id,
122-
to: users.map((user) => ({
123-
name: user.name ?? undefined,
124-
email: user.email,
125-
tags: [],
126-
})),
157+
to,
127158
});
128159
};
129160

@@ -207,6 +238,6 @@ export const sendActualUserTicketQREmails = async ({
207238

208239
await RPC_SERVICE_EMAIL.bulkSendUserQRTicketEmail({
209240
to,
210-
eventName: userTickets[0].ticketTemplate.event.name,
241+
ticketName: userTickets[0].ticketTemplate.name,
211242
});
212243
};

src/schema/invitations/mutations.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { GraphQLError } from "graphql";
44
import { builder } from "~/builder";
55
import {
66
insertUserTicketsSchema,
7-
selectUsersSchema,
87
selectUserTicketsSchema,
98
userTicketsSchema,
109
} from "~/datasources/db/schema";
@@ -13,7 +12,6 @@ import { sendTicketInvitationEmails } from "~/notifications/tickets";
1312
import { createInitialPurchaseOrder } from "~/schema/purchaseOrder/helpers";
1413
import { UserTicketRef } from "~/schema/shared/refs";
1514
import { ticketsFetcher } from "~/schema/ticket/ticketsFetcher";
16-
import { usersFetcher } from "~/schema/user/userFetcher";
1715

1816
const GiftTicketsToUserInput = builder.inputType("GiftTicketsToUserInput", {
1917
fields: (t) => ({
@@ -117,23 +115,14 @@ builder.mutationField("giftTicketsToUsers", (t) =>
117115
.returning();
118116

119117
if (notifyUsers) {
120-
const userIdsWithTickets = createdUserTickets
121-
.map((userTicket) => userTicket.userId)
122-
.filter(Boolean);
123-
const users = await usersFetcher.searchUsers({
124-
DB,
125-
search: {
126-
userIds: userIdsWithTickets,
127-
},
128-
});
129-
130-
const parsedUsers = users.map((user) => selectUsersSchema.parse(user));
118+
const userTicketIds = createdUserTickets.map(
119+
(userTicket) => userTicket.id,
120+
);
131121

132122
await sendTicketInvitationEmails({
133123
DB,
134124
logger,
135-
ticketId: ticket.id,
136-
users: parsedUsers,
125+
userTicketIds,
137126
RPC_SERVICE_EMAIL,
138127
});
139128
}

workers/transactional_email_service/index.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -235,30 +235,30 @@ export default class EmailService extends WorkerEntrypoint<ENV> {
235235
async bulkSendUserQRTicketEmail({
236236
// TODO: Change this image
237237
eventLogoCloudflareImageURL = DEFAULT_CLOUDFLARE_LOGO_URL,
238-
eventName,
238+
ticketName,
239239
to,
240240
}: {
241241
eventLogoCloudflareImageURL?: string;
242-
eventName: string;
242+
ticketName: string;
243243
to: (ReceiverType & { userTicketId: string })[];
244244
}) {
245245
this.logger.info(`About to send ConfirmationWaitlistAccepted`, {
246-
eventName,
246+
ticketName,
247247
});
248248
const resendArgs = to.map(
249249
(receiver) =>
250250
({
251251
htmlContent: render(
252252
<TicketConfirmation
253253
eventLogoCloudflareImageURL={eventLogoCloudflareImageURL}
254-
eventName={eventName}
254+
ticketName={ticketName}
255255
userTicketId={receiver.userTicketId}
256256
userName={receiver.name}
257257
userEmail={receiver.email}
258258
/>,
259259
),
260260
tags: receiver.tags,
261-
subject: `Tu ticket para ${eventName}`,
261+
subject: `Tu ticket para ${ticketName}`,
262262
to: [
263263
{
264264
name: receiver.name,
@@ -278,36 +278,33 @@ export default class EmailService extends WorkerEntrypoint<ENV> {
278278
async bulkSendEventTicketInvitations({
279279
// TODO: Change this image
280280
eventLogoCloudflareImageURL = DEFAULT_CLOUDFLARE_LOGO_URL,
281-
eventName,
282-
ticketId,
283-
eventId,
284281
to,
285282
}: {
286283
eventLogoCloudflareImageURL?: string;
287-
eventName: string;
288-
ticketId: string;
289-
eventId: string;
290-
to: ReceiverType[];
284+
to: (ReceiverType & {
285+
userTicketId: string;
286+
ticketName: string;
287+
ticketId: string;
288+
eventId: string;
289+
})[];
291290
}) {
292-
this.logger.info(`About to send batch EventInvitation`, {
293-
eventName,
294-
eventId,
295-
ticketId,
296-
});
291+
this.logger.info(
292+
`About to send bulkSendEventTicketInvitations to ${to.length} users`,
293+
);
297294

298295
const resendArgs = to.map(
299296
(receiver) =>
300297
({
301298
htmlContent: render(
302299
<EventInvitation
303300
eventLogoCloudflareImageURL={eventLogoCloudflareImageURL}
304-
eventName={eventName}
301+
ticketName={receiver.ticketName}
305302
userName={receiver.name}
306303
userEmail={receiver.email}
307304
/>,
308305
),
309306
tags: receiver.tags,
310-
subject: `Estás invitado a ${eventName}`,
307+
subject: `Estás invitado a ${receiver.ticketName}`,
311308
to: [
312309
{
313310
name: receiver.name,

0 commit comments

Comments
 (0)