From 2b91102f3fae0d60faf6cad78f40e6d1a3987838 Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Sat, 12 Nov 2022 13:46:27 -0300 Subject: [PATCH] Recurring emails fixed (#5499) --- apps/web/lib/mutations/bookings/create-recurring-booking.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/web/lib/mutations/bookings/create-recurring-booking.ts b/apps/web/lib/mutations/bookings/create-recurring-booking.ts index 2a51db8cd6..1485b8a1e4 100644 --- a/apps/web/lib/mutations/bookings/create-recurring-booking.ts +++ b/apps/web/lib/mutations/bookings/create-recurring-booking.ts @@ -17,9 +17,9 @@ const createRecurringBooking = async (data: ExtendedBookingCreateBody[]) => { let appsStatus: AppsStatus[] | undefined = undefined; // Reversing to accumulate results for noEmail instances first, to then lastly, create the // emailed booking taking into account accumulated results to send app status accurately - for (let key = 0; key < data.length; key++) { + for (let key = data.length - 1; key >= 0; key--) { const booking = data[key]; - if (key === data.length - 1) { + if (key === 0) { const calcAppsStatus: { [key: string]: AppsStatus } = createdBookings .flatMap((book) => (book.appsStatus !== undefined ? book.appsStatus : [])) .reduce((prev, curr) => { @@ -39,6 +39,7 @@ const createRecurringBooking = async (data: ExtendedBookingCreateBody[]) => { appsStatus, allRecurringDates, currentRecurringIndex: key, + noEmail: key !== 0, }); createdBookings.push(response); }