bookings are now added from fees array - for repeated bookings
This commit is contained in:
@@ -16,20 +16,67 @@ const fetchAllBookings = () => {
|
|||||||
|
|
||||||
bookingData.forEach((fullBookingEntry) => {
|
bookingData.forEach((fullBookingEntry) => {
|
||||||
const fees = fullBookingEntry && fullBookingEntry.fees ? fullBookingEntry.fees : [];
|
const fees = fullBookingEntry && fullBookingEntry.fees ? fullBookingEntry.fees : [];
|
||||||
const firstFee = fees.length > 0 && fees[0].fee ? fees[0].fee : undefined;
|
const startMoment = fullBookingEntry && fullBookingEntry.start && fullBookingEntry.start.dateTime ?
|
||||||
const hourlyRate = firstFee && firstFee.price ? firstFee.price : 0;
|
moment.utc(fullBookingEntry.start.dateTime) : null;
|
||||||
|
const endMoment = fullBookingEntry && fullBookingEntry.end && fullBookingEntry.end.dateTime ?
|
||||||
|
moment.utc(fullBookingEntry.end.dateTime) : null;
|
||||||
|
|
||||||
cleanedBookingReservations.push({
|
// console.log('\r\n\r\nStart : ', startMoment.clone().tz(fullBookingEntry.timezone).format('DD.MM. HH:mm'), '[', startMoment.toISOString(),']');
|
||||||
reservationId: fullBookingEntry['_id'],
|
// console.log('End : ', endMoment.clone().tz(fullBookingEntry.timezone).format('DD.MM. HH:mm'), '[', endMoment.toISOString(), ']');
|
||||||
memberId: fullBookingEntry.member,
|
// console.log('Fees : ');
|
||||||
officeId: fullBookingEntry.office,
|
|
||||||
resourceId: fullBookingEntry.resourceId,
|
fees.forEach((feeElement, index) => {
|
||||||
start: fullBookingEntry.start.dateTime,
|
const fee = feeElement.fee ? feeElement.fee : null;
|
||||||
end: fullBookingEntry.end.dateTime,
|
const dateMoment = feeElement.date ? moment.utc(feeElement.date) : null;
|
||||||
timezone: fullBookingEntry.timezone,
|
const feeId = fee && fee['_id'] ? fee['_id'] : '0';
|
||||||
canceled: fullBookingEntry.canceled || false,
|
const hourlyRate = fee && fee.price ? fee.price : 0;
|
||||||
hourlyRate,
|
|
||||||
|
if (startMoment && endMoment && dateMoment){
|
||||||
|
// console.log('\tOriginal date : ', dateMoment.format('DD.MM'));
|
||||||
|
|
||||||
|
const yearPart = dateMoment.year();
|
||||||
|
const monthPart = dateMoment.month();
|
||||||
|
const dayPart = dateMoment.date();
|
||||||
|
|
||||||
|
// console.log('\t\tYear part : ', yearPart);
|
||||||
|
// console.log('\t\tMonth part: ', monthPart);
|
||||||
|
// console.log('\t\tDay part : ', dayPart);
|
||||||
|
|
||||||
|
const newStartMoment = startMoment.clone().tz(fullBookingEntry.timezone).year(yearPart).month(monthPart).date(dayPart);
|
||||||
|
const newEndMoment = endMoment.clone().tz(fullBookingEntry.timezone).year(yearPart).month(monthPart).date(dayPart);
|
||||||
|
|
||||||
|
// console.log('\tNew start : ', newStartMoment.format('DD.MM. HH:mm'), '[', newStartMoment.toISOString(), ']');
|
||||||
|
// console.log('\tNew end : ', newEndMoment.format('DD.MM. HH:mm'), '[', newEndMoment.toISOString(), ']');
|
||||||
|
// console.log('\t----------------------------');
|
||||||
|
|
||||||
|
cleanedBookingReservations.push({
|
||||||
|
reservationId: `${fullBookingEntry['_id']}-${index}`,
|
||||||
|
memberId: fullBookingEntry.member,
|
||||||
|
officeId: fullBookingEntry.office,
|
||||||
|
resourceId: fullBookingEntry.resourceId,
|
||||||
|
start: newStartMoment.toISOString(),
|
||||||
|
end: newEndMoment.toISOString(),
|
||||||
|
timezone: fullBookingEntry.timezone,
|
||||||
|
canceled: fullBookingEntry.canceled || false,
|
||||||
|
hourlyRate,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (fees.length === 0){
|
||||||
|
cleanedBookingReservations.push({
|
||||||
|
reservationId: `${fullBookingEntry['_id']}-0`,
|
||||||
|
memberId: fullBookingEntry.member,
|
||||||
|
officeId: fullBookingEntry.office,
|
||||||
|
resourceId: fullBookingEntry.resourceId,
|
||||||
|
start: startMoment.toISOString(),
|
||||||
|
end: endMoment.toISOString(),
|
||||||
|
timezone: fullBookingEntry.timezone,
|
||||||
|
canceled: fullBookingEntry.canceled || false,
|
||||||
|
hourlyRate: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
resolve(cleanedBookingReservations);
|
resolve(cleanedBookingReservations);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user