bookings are now added from fees array - for repeated bookings
This commit is contained in:
@@ -16,20 +16,67 @@ const fetchAllBookings = () => {
|
||||
|
||||
bookingData.forEach((fullBookingEntry) => {
|
||||
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 startMoment = fullBookingEntry && fullBookingEntry.start && fullBookingEntry.start.dateTime ?
|
||||
moment.utc(fullBookingEntry.start.dateTime) : null;
|
||||
const endMoment = fullBookingEntry && fullBookingEntry.end && fullBookingEntry.end.dateTime ?
|
||||
moment.utc(fullBookingEntry.end.dateTime) : null;
|
||||
|
||||
cleanedBookingReservations.push({
|
||||
reservationId: fullBookingEntry['_id'],
|
||||
memberId: fullBookingEntry.member,
|
||||
officeId: fullBookingEntry.office,
|
||||
resourceId: fullBookingEntry.resourceId,
|
||||
start: fullBookingEntry.start.dateTime,
|
||||
end: fullBookingEntry.end.dateTime,
|
||||
timezone: fullBookingEntry.timezone,
|
||||
canceled: fullBookingEntry.canceled || false,
|
||||
hourlyRate,
|
||||
// console.log('\r\n\r\nStart : ', startMoment.clone().tz(fullBookingEntry.timezone).format('DD.MM. HH:mm'), '[', startMoment.toISOString(),']');
|
||||
// console.log('End : ', endMoment.clone().tz(fullBookingEntry.timezone).format('DD.MM. HH:mm'), '[', endMoment.toISOString(), ']');
|
||||
// console.log('Fees : ');
|
||||
|
||||
fees.forEach((feeElement, index) => {
|
||||
const fee = feeElement.fee ? feeElement.fee : null;
|
||||
const dateMoment = feeElement.date ? moment.utc(feeElement.date) : null;
|
||||
const feeId = fee && fee['_id'] ? fee['_id'] : '0';
|
||||
const hourlyRate = fee && fee.price ? fee.price : 0;
|
||||
|
||||
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);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user