Bug fix for bookings
This commit is contained in:
@@ -81,6 +81,8 @@ const UNSCHEDULED_CHARGE_PRICE = parseFloat(process.env.UNSCHEDULED_USE_CHARGE_P
|
|||||||
|
|
||||||
const BOOKING_CHANGE_PERCENTAGE_CHARGE = parseInt(process.env.BOOKING_CHANGE_PERCENTAGE_CHARGE) || 100;
|
const BOOKING_CHANGE_PERCENTAGE_CHARGE = parseInt(process.env.BOOKING_CHANGE_PERCENTAGE_CHARGE) || 100;
|
||||||
|
|
||||||
|
const ALLOWED_BOOKING_CANCELLATION_TIME= parseInt(process.env.ALLOWED_BOOKING_CANCELLATION_TIME) || 30;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
VALID_CSV_HEADERS,
|
VALID_CSV_HEADERS,
|
||||||
USER_ENTRY_EVENT,
|
USER_ENTRY_EVENT,
|
||||||
@@ -98,4 +100,5 @@ module.exports = {
|
|||||||
UNSCHEDULED_TIME_RESOLUTION,
|
UNSCHEDULED_TIME_RESOLUTION,
|
||||||
UNSCHEDULED_CHARGE_PRICE,
|
UNSCHEDULED_CHARGE_PRICE,
|
||||||
BOOKING_CHANGE_PERCENTAGE_CHARGE,
|
BOOKING_CHANGE_PERCENTAGE_CHARGE,
|
||||||
|
ALLOWED_BOOKING_CANCELLATION_TIME,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,3 +20,5 @@ UNLOCK_5=Price for unlocked door, sixth month
|
|||||||
UNLOCK_STREAK_REPAIR_AFTER=Number of months without incidents to reset user incident level
|
UNLOCK_STREAK_REPAIR_AFTER=Number of months without incidents to reset user incident level
|
||||||
|
|
||||||
BOOKING_CHANGE_PERCENTAGE_CHARGE=Percentage of hourly reate to apply for cancellation-like charges
|
BOOKING_CHANGE_PERCENTAGE_CHARGE=Percentage of hourly reate to apply for cancellation-like charges
|
||||||
|
|
||||||
|
ALLOWED_BOOKING_CANCELLATION_TIME=Time from creation (in minutes) in which cancellation is not charged
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
const db = require('../../models/index');
|
const db = require('../../models/index');
|
||||||
|
|
||||||
const { UI_TIMEZONE, BOOKING_CHANGE_PERCENTAGE_CHARGE, incidentType } = require('../../constants/constants');
|
const { UI_TIMEZONE, BOOKING_CHANGE_PERCENTAGE_CHARGE, ALLOWED_BOOKING_CANCELLATION_TIME, incidentType } = require('../../constants/constants');
|
||||||
|
|
||||||
const bulkWriteBookingChangeIncidents = (incidents) => {
|
const bulkWriteBookingChangeIncidents = (incidents) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -33,9 +33,10 @@ const chargeBookingChanges = (changes) => {
|
|||||||
|
|
||||||
const newStart = newReservation.start ? moment.utc(newReservation.start) : null;
|
const newStart = newReservation.start ? moment.utc(newReservation.start) : null;
|
||||||
const newEnd = newReservation.end ? moment.utc(newReservation.end) : null;
|
const newEnd = newReservation.end ? moment.utc(newReservation.end) : null;
|
||||||
|
const reservationCreationTimestamp = newReservation.createdAt ? moment.utc(newReservation.createdAt) : null;
|
||||||
|
|
||||||
const reservationTimezone = newReservation.timezone ? newReservation.timezone : UI_TIMEZONE;
|
const reservationTimezone = newReservation.timezone ? newReservation.timezone : UI_TIMEZONE;
|
||||||
const reservationHourlyRate = oldReservation.hourlyRate ? oldReservation.hourlyRate : undefined;
|
const reservationHourlyRate = oldReservation.hourlyRate ? oldReservation.hourlyRate : newReservation.hourlyRate;
|
||||||
const canceled = newReservation.canceled;
|
const canceled = newReservation.canceled;
|
||||||
|
|
||||||
if (oldStart && oldEnd && newStart && newEnd && reservationHourlyRate){
|
if (oldStart && oldEnd && newStart && newEnd && reservationHourlyRate){
|
||||||
@@ -96,21 +97,25 @@ const chargeBookingChanges = (changes) => {
|
|||||||
incidents.push(incident);
|
incidents.push(incident);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
const chargeFee = 2 * reservationHourlyRate * oldReservationLength * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
const differenceFromCreation = reservationCreationTimestamp.diff(moment.utc(), 'minutes');
|
||||||
const incident = {
|
|
||||||
reservationId,
|
|
||||||
memberId,
|
|
||||||
oldResourceId: oldResourceId || resourceId,
|
|
||||||
newResourceId: null,
|
|
||||||
oldBookingStart: oldReservation.start,
|
|
||||||
oldBookingEnd: oldReservation.end,
|
|
||||||
newBookingStart: null,
|
|
||||||
newBookingEnd: null,
|
|
||||||
incidentType: incidentType.BOOKING_CANCELED_LATE,
|
|
||||||
chargeFee,
|
|
||||||
};
|
|
||||||
|
|
||||||
incidents.push(incident);
|
if (differenceFromCreation > ALLOWED_BOOKING_CANCELLATION_TIME){
|
||||||
|
const chargeFee = 2 * reservationHourlyRate * oldReservationLength * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||||
|
const incident = {
|
||||||
|
reservationId,
|
||||||
|
memberId,
|
||||||
|
oldResourceId: oldResourceId || resourceId,
|
||||||
|
newResourceId: null,
|
||||||
|
oldBookingStart: oldReservation.start,
|
||||||
|
oldBookingEnd: oldReservation.end,
|
||||||
|
newBookingStart: null,
|
||||||
|
newBookingEnd: null,
|
||||||
|
incidentType: incidentType.BOOKING_CANCELED_LATE,
|
||||||
|
chargeFee,
|
||||||
|
};
|
||||||
|
|
||||||
|
incidents.push(incident);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.setDataValue('hourlyRate', previous.hourlyRate);
|
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
||||||
|
|
||||||
if (realChange){
|
if (realChange){
|
||||||
changes.push({
|
changes.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user