Editing of the fees before sending / bugfixes
This commit is contained in:
@@ -283,6 +283,22 @@ const deleteBookingChangeIncidentsById = (incidentIds) => {
|
||||
return db.bookingChangeIncident.update({deleted: true},{where: filters});
|
||||
};
|
||||
|
||||
const updateBookingChangeIncidentsById = (incidentFees) => {
|
||||
const incidentIds = Object.keys(incidentFees);
|
||||
|
||||
const asyncUpdateActions = [];
|
||||
|
||||
incidentIds.forEach((incidentId) => {
|
||||
const newFeeCharge = parseFloat(incidentFees[incidentId]);
|
||||
|
||||
if (newFeeCharge || (newFeeCharge === 0)){
|
||||
asyncUpdateActions.push(db.bookingChangeIncident.update({chargeFee: newFeeCharge}, {where: {id: incidentId}}));
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.all(asyncUpdateActions);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getChargedCanceledReservations,
|
||||
getIncidentsFromChanges,
|
||||
@@ -290,5 +306,6 @@ module.exports = {
|
||||
getShorteningIncidentsForReservationId,
|
||||
getReservationsIncidentsForRemoval,
|
||||
deleteBookingChangeIncidents,
|
||||
deleteBookingChangeIncidentsById
|
||||
deleteBookingChangeIncidentsById,
|
||||
updateBookingChangeIncidentsById
|
||||
};
|
||||
|
||||
@@ -80,6 +80,26 @@ const deleteUnscheduledIncidentsById = (incidentIds) => {
|
||||
return db.unscheduledIncident.update({deleted: true},{where: filters});
|
||||
};
|
||||
|
||||
const updateUnscheduledIncidentsById = (incidentFees) => {
|
||||
const incidentIds = Object.keys(incidentFees);
|
||||
|
||||
const asyncUpdateActions = [];
|
||||
|
||||
incidentIds.forEach((incidentId) => {
|
||||
const newFeeCharge = parseFloat(incidentFees[incidentId]);
|
||||
|
||||
if (newFeeCharge || (newFeeCharge === 0)){
|
||||
asyncUpdateActions.push(db.unscheduledIncident.update({
|
||||
totalChargeFee: newFeeCharge,
|
||||
chargePrice: newFeeCharge,
|
||||
timeIntervalsToCharge: 1
|
||||
}, {where: {id: incidentId}}));
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.all(asyncUpdateActions);
|
||||
};
|
||||
|
||||
const insertUnlockedIncidents = (incidents) => {
|
||||
const asyncJobs = [];
|
||||
incidents.forEach((incident) => {
|
||||
@@ -106,7 +126,6 @@ const insertUnlockedIncidents = (incidents) => {
|
||||
bookingStart: start,
|
||||
bookingEnd: end,
|
||||
unlockTimestamp,
|
||||
incidentLevel,
|
||||
},
|
||||
defaults: {...incidentForDB},
|
||||
}));
|
||||
@@ -124,6 +143,22 @@ const deleteUnlockedIncidentsById = (incidentIds) => {
|
||||
return db.unlockedIncident.update({deleted: true},{where: filters});
|
||||
};
|
||||
|
||||
const updateUnlockedIncidentsById = (incidentFees) => {
|
||||
const incidentIds = Object.keys(incidentFees);
|
||||
|
||||
const asyncUpdateActions = [];
|
||||
|
||||
incidentIds.forEach((incidentId) => {
|
||||
const newFeeCharge = parseFloat(incidentFees[incidentId]);
|
||||
|
||||
if (newFeeCharge || (newFeeCharge === 0)){
|
||||
asyncUpdateActions.push(db.unlockedIncident.update({incidentLevelPrice: newFeeCharge}, {where: {id: incidentId}}));
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.all(asyncUpdateActions);
|
||||
};
|
||||
|
||||
const setUnlockedIncidentsLevel = (incidents) => {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const sortingFunction = (incidentA, incidentB) => {
|
||||
@@ -162,7 +197,7 @@ const setUnlockedIncidentsLevel = (incidents) => {
|
||||
const incidentsWithLevel = [];
|
||||
|
||||
incidents.forEach((incident) => {
|
||||
const memberLastIncident = membersLastIncident[incident.memberId];
|
||||
const memberLastIncident = Object.assign({}, membersLastIncident[incident.memberId]);
|
||||
|
||||
const formattedIncident = {
|
||||
reservation: incident.reservation,
|
||||
@@ -850,5 +885,7 @@ const calculateDoorLockCharges = () => {
|
||||
module.exports = {
|
||||
calculateDoorLockCharges,
|
||||
deleteUnlockedIncidentsById,
|
||||
deleteUnscheduledIncidentsById
|
||||
deleteUnscheduledIncidentsById,
|
||||
updateUnlockedIncidentsById,
|
||||
updateUnscheduledIncidentsById
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user