mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-02 18:51:52 +02:00
⚡️ Send finalization emails asynchronously (#1095)
This commit is contained in:
parent
615c43d777
commit
2b11c47a97
3 changed files with 44 additions and 33 deletions
|
@ -1,5 +1,6 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { waitUntil } from "@vercel/functions";
|
||||
import dayjs from "dayjs";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import toArray from "dayjs/plugin/toArray";
|
||||
|
@ -131,16 +132,18 @@ export const polls = router({
|
|||
});
|
||||
|
||||
if (user) {
|
||||
await ctx.emailClient.sendTemplate("NewPollEmail", {
|
||||
to: user.email,
|
||||
subject: `Let's find a date for ${poll.title}`,
|
||||
props: {
|
||||
title: poll.title,
|
||||
name: user.name,
|
||||
adminLink: pollLink,
|
||||
participantLink,
|
||||
},
|
||||
});
|
||||
waitUntil(
|
||||
ctx.emailClient.sendTemplate("NewPollEmail", {
|
||||
to: user.email,
|
||||
subject: `Let's find a date for ${poll.title}`,
|
||||
props: {
|
||||
title: poll.title,
|
||||
name: user.name,
|
||||
adminLink: pollLink,
|
||||
participantLink,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -875,28 +878,30 @@ export const polls = router({
|
|||
});
|
||||
}
|
||||
|
||||
const emailToHost = ctx.emailClient.sendTemplate("FinalizeHostEmail", {
|
||||
subject: `Date booked for ${poll.title}`,
|
||||
to: poll.user.email,
|
||||
props: {
|
||||
name: poll.user.name,
|
||||
pollUrl: ctx.absoluteUrl(`/poll/${poll.id}`),
|
||||
location: poll.location,
|
||||
title: poll.title,
|
||||
attendees: poll.participants
|
||||
.filter((p) =>
|
||||
p.votes.some(
|
||||
(v) => v.optionId === input.optionId && v.type !== "no",
|
||||
),
|
||||
)
|
||||
.map((p) => p.name),
|
||||
date,
|
||||
day,
|
||||
dow,
|
||||
time,
|
||||
},
|
||||
attachments: [{ filename: "event.ics", content: event.value }],
|
||||
});
|
||||
const emailToHost = waitUntil(
|
||||
ctx.emailClient.sendTemplate("FinalizeHostEmail", {
|
||||
subject: `Date booked for ${poll.title}`,
|
||||
to: poll.user.email,
|
||||
props: {
|
||||
name: poll.user.name,
|
||||
pollUrl: ctx.absoluteUrl(`/poll/${poll.id}`),
|
||||
location: poll.location,
|
||||
title: poll.title,
|
||||
attendees: poll.participants
|
||||
.filter((p) =>
|
||||
p.votes.some(
|
||||
(v) => v.optionId === input.optionId && v.type !== "no",
|
||||
),
|
||||
)
|
||||
.map((p) => p.name),
|
||||
date,
|
||||
day,
|
||||
dow,
|
||||
time,
|
||||
},
|
||||
attachments: [{ filename: "event.ics", content: event.value }],
|
||||
}),
|
||||
);
|
||||
|
||||
const emailsToParticipants = participantsToEmail.map((p) => {
|
||||
return ctx.emailClient.sendTemplate("FinalizeParticipantEmail", {
|
||||
|
@ -924,7 +929,7 @@ export const polls = router({
|
|||
});
|
||||
});
|
||||
|
||||
await Promise.all([emailToHost, ...emailsToParticipants]);
|
||||
waitUntil(Promise.all([emailToHost, ...emailsToParticipants]));
|
||||
}
|
||||
}),
|
||||
reopen: possiblyPublicProcedure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue