From ed6cc5a1bc02a6b493f1a79f0e75e3eb8c86e872 Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Sun, 19 Jan 2020 11:39:09 +0100 Subject: [PATCH] Bug fixes --- services/officeRnD/bookings.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/services/officeRnD/bookings.js b/services/officeRnD/bookings.js index 5d390a6..3110187 100644 --- a/services/officeRnD/bookings.js +++ b/services/officeRnD/bookings.js @@ -22,6 +22,21 @@ const fetchAllBookings = () => { return; } const fees = fullBookingEntry.fees ? fullBookingEntry.fees : []; + const canceled = fullBookingEntry.canceled ? fullBookingEntry.canceled : false; + const recurringReservation = fullBookingEntry.recurrence && fullBookingEntry.recurrence.rrule ? + fullBookingEntry.recurrence.rrule : null; + const tentative = fullBookingEntry.tentative ? fullBookingEntry.tentative : false; + const free = fullBookingEntry.free ? fullBookingEntry.free : false; + + //Special case, canceled recurring reservation + //It has empty fees array (fees.length = 0) and no "canceled" field + //Normally, canceled reservation has canceled field + //Also, it has rrule !== null + //If it is tentative, it will have tentative = true, skip those (do not delete) + //If it is free, it will have free = true, skip those (do not delete) + if (fees.length === 0 && !canceled && recurringReservation && !tentative && !free){ + bookingIdsToRemove.push(fullBookingEntry['_id']); + } if (fees.length > 1){ // Recurring booking, let's create new booking @@ -101,6 +116,8 @@ const fetchAllBookings = () => { const fees = fullBookingEntry && fullBookingEntry.fees ? fullBookingEntry.fees : []; const firstFee = fees.length > 0 && fees[0].fee ? fees[0].fee : undefined; const hourlyRate = firstFee && firstFee.price ? firstFee.price : 0; + const free = fullBookingEntry.free ? fullBookingEntry.free : false; + const tentative = fullBookingEntry.tentative ? fullBookingEntry.tentative : false; const startMoment = fullBookingEntry && fullBookingEntry.start && fullBookingEntry.start.dateTime ? moment.utc(fullBookingEntry.start.dateTime) : null; @@ -111,7 +128,7 @@ const fetchAllBookings = () => { // console.log('End : ', endMoment.clone().tz(fullBookingEntry.timezone).format('DD.MM. HH:mm'), '[', endMoment.toISOString(), ']'); // console.log('Fees : '); - if (startMoment && endMoment){ + if (startMoment && endMoment && !free && !tentative){ cleanedBookingReservations.push({ reservationId: fullBookingEntry['_id'], memberId: fullBookingEntry.member,