implement backend methods to update incident fees

This commit is contained in:
Bilal Catic
2020-01-09 01:33:19 +01:00
parent ff8a836fed
commit 1a21e91796
4 changed files with 120 additions and 8 deletions

View File

@@ -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 = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null;
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
};

View File

@@ -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 = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null;
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) => {
@@ -124,6 +144,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 = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null;
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) => {
@@ -850,5 +886,7 @@ const calculateDoorLockCharges = () => {
module.exports = {
calculateDoorLockCharges,
deleteUnlockedIncidentsById,
deleteUnscheduledIncidentsById
deleteUnscheduledIncidentsById,
updateUnlockedIncidentsById,
updateUnscheduledIncidentsById
};