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

@@ -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,49 @@ const deleteFees= (req, res) => {
}
};
const updateFees = (req, res) => {
const updateData = req.body;
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 +325,6 @@ module.exports = {
addFees,
checkProcessingStatus,
getPracticeSummaryReport,
deleteFees
deleteFees,
updateFees
};