Editing of the fees before sending / bugfixes

This commit is contained in:
Senad Uka
2020-01-13 07:56:00 +01:00
parent 404f27e208
commit 3d8e9c987f
6 changed files with 281 additions and 22 deletions

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 = 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
};