From c4c5e83499d7f9d8bcc34b3da6ede2b0c111dd79 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Tue, 1 Jun 2021 19:16:06 +0000 Subject: [PATCH] Disables booking confirmation for Office 365 & enable new event email for all --- lib/calendarClient.ts | 18 ++++++++++++------ pages/api/book/[user].ts | 9 +++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/calendarClient.ts b/lib/calendarClient.ts index fe1e7111b3..855ed6ea7b 100644 --- a/lib/calendarClient.ts +++ b/lib/calendarClient.ts @@ -135,7 +135,10 @@ const MicrosoftOffice365Calendar = (credential): CalendarApiAdapter => { 'Content-Type': 'application/json', }, body: JSON.stringify(translateEvent(event)) - }).then(handleErrors)) + }).then(handleErrors).then( (responseBody) => ({ + ...responseBody, + disableConfirmationEmail: true, + }))) } }; @@ -228,14 +231,17 @@ const getBusyTimes = (withCredentials, dateFrom, dateTo) => Promise.all( (results) => results.reduce( (acc, availability) => acc.concat(availability), []) ); -const createEvent = (credential, calEvent: CalendarEvent) => { - if (credential) { - return calendars([credential])[0].createEvent(calEvent); - } - // send email if no Calendar integration is found for now. +const createEvent = (credential, calEvent: CalendarEvent): Promise => { + createNewEventEmail( calEvent, ); + + if (credential) { + return calendars([credential])[0].createEvent(calEvent); + } + + return Promise.resolve({}); }; export { getBusyTimes, createEvent, CalendarEvent }; diff --git a/pages/api/book/[user].ts b/pages/api/book/[user].ts index 9d55b1575f..7abeadf1c8 100644 --- a/pages/api/book/[user].ts +++ b/pages/api/book/[user].ts @@ -31,12 +31,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ] }; - // TODO: for now, first integration created; primary = obvious todo; ability to change primary. const result = await createEvent(currentUser.credentials[0], evt); - createConfirmBookedEmail( - evt - ); + if (!result.disableConfirmationEmail) { + createConfirmBookedEmail( + evt + ); + } res.status(200).json(result); }