Append reschedule/cancel also to event description

This commit is contained in:
nicolas committed 2021-06-13 00:37:35 +02:00
1 parent a231ee6c0d
commit 8227e733e6
2 files changed
+25 -18

No files matched your search

+15 -4
View File
@@ -39,7 +39,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
]
};
const hashUID = translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));
const hashUID: string = translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));
const cancelLink: string = process.env.BASE_URL + '/cancel/' + hashUID;
const rescheduleLink:string = process.env.BASE_URL + '/reschedule/' + hashUID;
const appendLinksToEvents = (event: CalendarEvent) => {
const eventCopy = {...event};
eventCopy.description += "\n\n"
+ "Need to change this event?\n"
+ "Cancel: " + cancelLink + "\n"
+ "Reschedule:" + rescheduleLink;
return eventCopy;
}
const eventType = await prisma.eventType.findFirst({
where: {
@@ -75,7 +86,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// Use all integrations
results = await async.mapLimit(currentUser.credentials, 5, async (credential) => {
const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
return await updateEvent(credential, bookingRefUid, evt)
return await updateEvent(credential, bookingRefUid, appendLinksToEvents(evt))
});
// Clone elements
@@ -106,7 +117,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
} else {
// Schedule event
results = await async.mapLimit(currentUser.credentials, 5, async (credential) => {
const response = await createEvent(credential, evt);
const response = await createEvent(credential, appendLinksToEvents(evt));
return {
type: credential.type,
response
@@ -144,7 +155,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// If one of the integrations allows email confirmations or no integrations are added, send it.
if (currentUser.credentials.length === 0 || !results.every((result) => result.disableConfirmationEmail)) {
await createConfirmBookedEmail(
evt, hashUID
evt, cancelLink, rescheduleLink
);
}