add deleteFees route and implement logic

This commit is contained in:
Bilal Catic
2019-11-21 07:12:50 +01:00
parent 3d051766b1
commit 8a3db0d481
4 changed files with 76 additions and 1 deletions

View File

@@ -9,6 +9,8 @@ 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 { UI_TIMEZONE, DEFAULT_DATE_FORMAT, ALLOW_SENDING_FEES, integrationServiceErrors } = require('../constants/constants');
@@ -80,6 +82,8 @@ const updateMapping = (req, res) => {
};
const getAllIncidentsController = (req, res) => {
console.log('get all incidents : ');
console.log(req.params);
const dateRange = {
startDate: req.params.startDate,
endDate: req.params.endDate,
@@ -175,6 +179,40 @@ const addFees = (req, res) => {
}
};
const deleteFees= (req, res) => {
const deleteData = req.body;
console.log('Delete fees request : ');
console.log(req.body);
const dateRange = deleteData.dateRange ? deleteData.dateRange : null;
const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null;
const unlockedIncidentIds = incidents.unlockedIncidentIds ? incidents.unlockedIncidentIds : [];
const unscheduledIncidentIds = incidents.unscheduledIncidentIds ? incidents.unscheduledIncidentIds : [];
const bookingChangeIncidentIds = incidents.bookingChangeIncidentIds ? incidents.bookingChangeIncidentIds : [];
req.params.startDate = dateRange.startDate ? dateRange.startDate : null;
req.params.endDate = dateRange.endDate ? dateRange.endDate : null;
if (Array.isArray(unlockedIncidentIds) && Array.isArray(unscheduledIncidentIds) && Array.isArray(bookingChangeIncidentIds)){
const asyncDeleteActions = [
deleteUnlockedIncidentsById(unlockedIncidentIds),
deleteUnscheduledIncidentsById(unscheduledIncidentIds),
deleteBookingChangeIncidentsById(bookingChangeIncidentIds)
];
Promise.all(asyncDeleteActions)
.then(() => {
getAllIncidentsController(req, res);
})
.catch((error) => {
console.log('Error deleting incidents : ', error);
res.status(500).send();
});
}else{
getAllIncidentsController(req, res);
}
};
const checkProcessingStatus = (req, res) => {
checkIfProcessing()
.then((processing) => {
@@ -227,4 +265,5 @@ module.exports = {
addFees,
checkProcessingStatus,
getPracticeSummaryReport,
deleteFees
};