implement backend methods to update incident fees
This commit is contained in:
@@ -2,15 +2,25 @@
|
|||||||
|
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
|
|
||||||
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase, deleteMappingById, updateMappingById } = require('../services/officeRnD/resources');
|
const {
|
||||||
|
getMappingsFromDatabase,
|
||||||
|
fetchOffices,
|
||||||
|
fetchResources,
|
||||||
|
saveNewMappingToDatabase,
|
||||||
|
deleteMappingById,
|
||||||
|
updateMappingById } = require('../services/officeRnD/resources');
|
||||||
const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports');
|
const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports');
|
||||||
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
|
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
|
||||||
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
|
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
|
||||||
const { reformatMembershipsName } = require('../services/officeRnD/memberships');
|
const { reformatMembershipsName } = require('../services/officeRnD/memberships');
|
||||||
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
||||||
const { checkIfProcessing } = require('../services/integration/processingStatus');
|
const { checkIfProcessing } = require('../services/integration/processingStatus');
|
||||||
const { deleteUnlockedIncidentsById, deleteUnscheduledIncidentsById } = require('../services/integration/doorLockCharges');
|
const {
|
||||||
const { deleteBookingChangeIncidentsById } = require('../services/integration/bookingChangeCharges');
|
deleteUnlockedIncidentsById,
|
||||||
|
deleteUnscheduledIncidentsById,
|
||||||
|
updateUnscheduledIncidentsById,
|
||||||
|
updateUnlockedIncidentsById } = require('../services/integration/doorLockCharges');
|
||||||
|
const { deleteBookingChangeIncidentsById, updateBookingChangeIncidentsById } = require('../services/integration/bookingChangeCharges');
|
||||||
|
|
||||||
const { UI_TIMEZONE, DEFAULT_DATE_FORMAT, ALLOW_SENDING_FEES, integrationServiceErrors } = require('../constants/constants');
|
const { UI_TIMEZONE, DEFAULT_DATE_FORMAT, ALLOW_SENDING_FEES, integrationServiceErrors } = require('../constants/constants');
|
||||||
|
|
||||||
@@ -177,7 +187,7 @@ const addFees = (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteFees= (req, res) => {
|
const deleteFees = (req, res) => {
|
||||||
const deleteData = req.body;
|
const deleteData = req.body;
|
||||||
const dateRange = deleteData.dateRange ? deleteData.dateRange : null;
|
const dateRange = deleteData.dateRange ? deleteData.dateRange : null;
|
||||||
const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null;
|
const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null;
|
||||||
@@ -220,6 +230,50 @@ const deleteFees= (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateFees = (req, res) => {
|
||||||
|
const updateData = req.body;
|
||||||
|
console.log(updateData);
|
||||||
|
const dateRange = updateData.dateRange ? updateData.dateRange : null;
|
||||||
|
const incidents = updateData.updatedIncidentsData ? updateData.updatedIncidentsData : null;
|
||||||
|
const memberId = updateData.memberId ? updateData.memberId : null;
|
||||||
|
|
||||||
|
const unlockedIncidentFees = incidents.unlockedIncidentFees ? incidents.unlockedIncidentFees : {};
|
||||||
|
const unscheduledIncidentFees = incidents.unscheduledIncidentFees ? incidents.unscheduledIncidentFees : {};
|
||||||
|
const bookingChangeIncidentFees = incidents.bookingChangeIncidentFees ? incidents.bookingChangeIncidentFees : {};
|
||||||
|
|
||||||
|
req.params.startDate = dateRange.startDate ? dateRange.startDate : null;
|
||||||
|
req.params.endDate = dateRange.endDate ? dateRange.endDate : null;
|
||||||
|
|
||||||
|
if (unlockedIncidentFees && unscheduledIncidentFees && bookingChangeIncidentFees){
|
||||||
|
const asyncUpdateActions = [
|
||||||
|
updateUnlockedIncidentsById(unlockedIncidentFees),
|
||||||
|
updateUnscheduledIncidentsById(unscheduledIncidentFees),
|
||||||
|
updateBookingChangeIncidentsById(bookingChangeIncidentFees)
|
||||||
|
];
|
||||||
|
|
||||||
|
Promise.all(asyncUpdateActions)
|
||||||
|
.then(() => {
|
||||||
|
if (memberId){
|
||||||
|
req.params.memberId = memberId;
|
||||||
|
getMemberIncidents(req, res);
|
||||||
|
}else{
|
||||||
|
getAllIncidentsController(req, res);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error updating incidents : ', error);
|
||||||
|
res.status(500).send();
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
if (memberId){
|
||||||
|
req.params.memberId = memberId;
|
||||||
|
getMemberIncidents(req, res);
|
||||||
|
}else{
|
||||||
|
getAllIncidentsController(req, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const checkProcessingStatus = (req, res) => {
|
const checkProcessingStatus = (req, res) => {
|
||||||
checkIfProcessing()
|
checkIfProcessing()
|
||||||
.then((processing) => {
|
.then((processing) => {
|
||||||
@@ -272,5 +326,6 @@ module.exports = {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
deleteFees
|
deleteFees,
|
||||||
|
updateFees
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ const {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
deleteFees
|
deleteFees,
|
||||||
|
updateFees
|
||||||
} = require('../controllers/integration');
|
} = require('../controllers/integration');
|
||||||
|
|
||||||
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
||||||
@@ -36,6 +37,7 @@ router.get('/officeRnD/membersList', fetchMembersList);
|
|||||||
|
|
||||||
router.post('/integration/addFees', addFees);
|
router.post('/integration/addFees', addFees);
|
||||||
router.delete('/integration/fees', deleteFees);
|
router.delete('/integration/fees', deleteFees);
|
||||||
|
router.patch('/integration/fees', updateFees);
|
||||||
|
|
||||||
router.get('/integration/processing', checkProcessingStatus);
|
router.get('/integration/processing', checkProcessingStatus);
|
||||||
|
|
||||||
|
|||||||
@@ -283,6 +283,22 @@ const deleteBookingChangeIncidentsById = (incidentIds) => {
|
|||||||
return db.bookingChangeIncident.update({deleted: true},{where: filters});
|
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 = {
|
module.exports = {
|
||||||
getChargedCanceledReservations,
|
getChargedCanceledReservations,
|
||||||
getIncidentsFromChanges,
|
getIncidentsFromChanges,
|
||||||
@@ -290,5 +306,6 @@ module.exports = {
|
|||||||
getShorteningIncidentsForReservationId,
|
getShorteningIncidentsForReservationId,
|
||||||
getReservationsIncidentsForRemoval,
|
getReservationsIncidentsForRemoval,
|
||||||
deleteBookingChangeIncidents,
|
deleteBookingChangeIncidents,
|
||||||
deleteBookingChangeIncidentsById
|
deleteBookingChangeIncidentsById,
|
||||||
|
updateBookingChangeIncidentsById
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -80,6 +80,26 @@ const deleteUnscheduledIncidentsById = (incidentIds) => {
|
|||||||
return db.unscheduledIncident.update({deleted: true},{where: filters});
|
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 insertUnlockedIncidents = (incidents) => {
|
||||||
const asyncJobs = [];
|
const asyncJobs = [];
|
||||||
incidents.forEach((incident) => {
|
incidents.forEach((incident) => {
|
||||||
@@ -124,6 +144,22 @@ const deleteUnlockedIncidentsById = (incidentIds) => {
|
|||||||
return db.unlockedIncident.update({deleted: true},{where: filters});
|
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) => {
|
const setUnlockedIncidentsLevel = (incidents) => {
|
||||||
return new Promise ((resolve, reject) => {
|
return new Promise ((resolve, reject) => {
|
||||||
const sortingFunction = (incidentA, incidentB) => {
|
const sortingFunction = (incidentA, incidentB) => {
|
||||||
@@ -850,5 +886,7 @@ const calculateDoorLockCharges = () => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
calculateDoorLockCharges,
|
calculateDoorLockCharges,
|
||||||
deleteUnlockedIncidentsById,
|
deleteUnlockedIncidentsById,
|
||||||
deleteUnscheduledIncidentsById
|
deleteUnscheduledIncidentsById,
|
||||||
|
updateUnlockedIncidentsById,
|
||||||
|
updateUnscheduledIncidentsById
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user