fix non-returning promise warning
This commit is contained in:
@@ -12,22 +12,22 @@ const {
|
||||
incidentType
|
||||
} = require('../../constants/constants');
|
||||
|
||||
|
||||
const bulkWriteBookingChangeIncidents = (incidents) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const asyncJobs = [];
|
||||
|
||||
incidents.forEach((incident) => {
|
||||
asyncJobs.push(db.bookingChangeIncident.findOrCreate({where: incident, defaults: incident}));
|
||||
});
|
||||
|
||||
Promise.all(asyncJobs)
|
||||
.then(() => {
|
||||
resolve();
|
||||
})
|
||||
.then(() => resolve())
|
||||
.catch((error) => reject(error));
|
||||
});
|
||||
};
|
||||
|
||||
const chargeBookingChanges = (changes) => {
|
||||
const getIncidentsFromChanges = (changes) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (Array.isArray(changes)){
|
||||
const incidents = [];
|
||||
@@ -52,21 +52,45 @@ const chargeBookingChanges = (changes) => {
|
||||
|
||||
const differenceFromNow = oldStart.diff(moment.utc(), 'minutes');
|
||||
|
||||
console.log('Change detected : ');
|
||||
console.log('\tOld reservation :');
|
||||
console.log('\t\tResource : ', oldResourceId);
|
||||
console.log('\t\tStart : ', oldStart.format());
|
||||
console.log('\t\tEnd : ', oldEnd.format());
|
||||
console.log('\t\tLength : ', oldReservationLength);
|
||||
console.log('\tNew Reservation :');
|
||||
console.log('\t\tResource : ', newReservation.resourceId);
|
||||
console.log('\t\tStart : ', newStart.format());
|
||||
console.log('\t\tEnd : ', newEnd.format());
|
||||
console.log('\t\tLength : ', newReservationLength);
|
||||
console.log('\t\tCanceled : ', canceled);
|
||||
console.log('\t---------------------------------');
|
||||
console.log('\tDifference : ', differenceFromNow, 'minutes');
|
||||
console.log('');
|
||||
console.log('\tIs booking changed too late ? ', differenceFromNow, ' < ', CHARGE_BOOKING_CHANGE_UNDER_TIME);
|
||||
if (differenceFromNow < CHARGE_BOOKING_CHANGE_UNDER_TIME){
|
||||
const { reservationId, memberId, resourceId } = newReservation;
|
||||
|
||||
console.log('\t\tYes');
|
||||
|
||||
console.log('\tIs booking canceled ?');
|
||||
if (!canceled) {
|
||||
console.log('\t\tNo');
|
||||
// Check if new reservation is on same day
|
||||
const sameDay = oldStart.tz(reservationTimezone).isSame(newStart.tz(reservationTimezone), 'day');
|
||||
|
||||
console.log('\tIs new reservation on the same day ?');
|
||||
if (sameDay) {
|
||||
console.log('\t\tYes');
|
||||
// Reservation moved in same day
|
||||
// Check if member shortened the reservation
|
||||
|
||||
console.log('\tIs reservation shortened ? ', newReservationLength, ' < ', oldReservationLength);
|
||||
if (newReservationLength < oldReservationLength) {
|
||||
console.log('\t\tYes');
|
||||
const differenceInLength = oldReservationLength - newReservationLength;
|
||||
const chargeFee = differenceInLength * reservationHourlyRate * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||
|
||||
console.log('\t\t\tThis is [shortened] incident ! Charge fee : ', chargeFee);
|
||||
const incident = {
|
||||
reservationId,
|
||||
memberId,
|
||||
@@ -81,12 +105,15 @@ const chargeBookingChanges = (changes) => {
|
||||
};
|
||||
|
||||
incidents.push(incident);
|
||||
}else{
|
||||
console.log('\t\tNo');
|
||||
}
|
||||
} else {
|
||||
console.log('\t\tNo');
|
||||
// Reservation moved to another day
|
||||
// Add cancellation charge
|
||||
const chargeFee = oldReservationLength * reservationHourlyRate * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||
|
||||
console.log('\t\t\tThis is incident ! Charge fee : ', chargeFee);
|
||||
const incident = {
|
||||
reservationId,
|
||||
memberId,
|
||||
@@ -103,10 +130,15 @@ const chargeBookingChanges = (changes) => {
|
||||
incidents.push(incident);
|
||||
}
|
||||
}else{
|
||||
console.log('\t\tYes');
|
||||
const differenceFromCreation = moment.utc().diff(reservationCreationTimestamp, 'minutes');
|
||||
|
||||
console.log('\tIs booking created in past ', ALLOWED_BOOKING_CANCELLATION_TIME, ' minutes ?', differenceFromCreation, ' > ', ALLOWED_BOOKING_CANCELLATION_TIME);
|
||||
if (differenceFromCreation > ALLOWED_BOOKING_CANCELLATION_TIME){
|
||||
console.log('\t\tYes');
|
||||
const chargeFee = reservationHourlyRate * oldReservationLength * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||
|
||||
console.log('\t\t\tThis is [cancellation] incident ! charge fee : ', chargeFee);
|
||||
const incident = {
|
||||
reservationId,
|
||||
memberId,
|
||||
@@ -124,10 +156,14 @@ const chargeBookingChanges = (changes) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
console.log('\t\tNo');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
resolve(bulkWriteBookingChangeIncidents(incidents));
|
||||
|
||||
resolve(incidents);
|
||||
}else{
|
||||
reject('Input argument is not an array !');
|
||||
}
|
||||
@@ -148,6 +184,7 @@ const getChargedCanceledReservations = (reservationIds) => {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
chargeBookingChanges,
|
||||
getChargedCanceledReservations,
|
||||
getIncidentsFromChanges,
|
||||
bulkWriteBookingChangeIncidents,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user