implement backend methods to update incident fees
This commit is contained in:
@@ -2,15 +2,25 @@
|
||||
|
||||
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 { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
|
||||
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
|
||||
const { reformatMembershipsName } = require('../services/officeRnD/memberships');
|
||||
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
||||
const { checkIfProcessing } = require('../services/integration/processingStatus');
|
||||
const { deleteUnlockedIncidentsById, deleteUnscheduledIncidentsById } = require('../services/integration/doorLockCharges');
|
||||
const { deleteBookingChangeIncidentsById } = require('../services/integration/bookingChangeCharges');
|
||||
const {
|
||||
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');
|
||||
|
||||
@@ -177,7 +187,7 @@ const addFees = (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const deleteFees= (req, res) => {
|
||||
const deleteFees = (req, res) => {
|
||||
const deleteData = req.body;
|
||||
const dateRange = deleteData.dateRange ? deleteData.dateRange : 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) => {
|
||||
checkIfProcessing()
|
||||
.then((processing) => {
|
||||
@@ -272,5 +326,6 @@ module.exports = {
|
||||
addFees,
|
||||
checkProcessingStatus,
|
||||
getPracticeSummaryReport,
|
||||
deleteFees
|
||||
deleteFees,
|
||||
updateFees
|
||||
};
|
||||
|
||||
@@ -13,7 +13,8 @@ const {
|
||||
addFees,
|
||||
checkProcessingStatus,
|
||||
getPracticeSummaryReport,
|
||||
deleteFees
|
||||
deleteFees,
|
||||
updateFees
|
||||
} = require('../controllers/integration');
|
||||
|
||||
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
||||
@@ -36,6 +37,7 @@ router.get('/officeRnD/membersList', fetchMembersList);
|
||||
|
||||
router.post('/integration/addFees', addFees);
|
||||
router.delete('/integration/fees', deleteFees);
|
||||
router.patch('/integration/fees', updateFees);
|
||||
|
||||
router.get('/integration/processing', checkProcessingStatus);
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user