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

View File

@@ -13,6 +13,7 @@ const {
addFees,
checkProcessingStatus,
getPracticeSummaryReport,
deleteFees
} = require('../controllers/integration');
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
@@ -34,6 +35,7 @@ router.get('/integration/report/allIncidents/:startDate/:endDate', getAllInciden
router.get('/officeRnD/membersList', fetchMembersList);
router.post('/integration/addFees', addFees);
router.delete('/integration/fees', deleteFees);
router.get('/integration/processing', checkProcessingStatus);

View File

@@ -274,6 +274,16 @@ const deleteBookingChangeIncidents = (incidents) => {
return Promise.all(asyncActions);
};
const deleteBookingChangeIncidentsById = (incidentIds) => {
console.log('Delete booking changes in DB :', incidentIds);
const filters = {
id: {
[Op.in]: incidentIds
}
};
return db.bookingChangeIncident.update({deleted: true},{where: filters});
};
module.exports = {
getChargedCanceledReservations,
getIncidentsFromChanges,
@@ -281,4 +291,5 @@ module.exports = {
getShorteningIncidentsForReservationId,
getReservationsIncidentsForRemoval,
deleteBookingChangeIncidents,
deleteBookingChangeIncidentsById
};

View File

@@ -2,6 +2,7 @@
const moment = require('moment-timezone');
const db = require('../../models/index');
const Op = require('sequelize').Op;
const {
doorLockEvents,
@@ -69,6 +70,16 @@ const insertUnscheduledIncidents = (incidents) => {
return Promise.all(asyncJobs);
};
const deleteUnscheduledIncidentsById = (incidentIds) => {
console.log('Delete unscheduled in DB :', incidentIds);
const filters = {
id: {
[Op.in]: incidentIds
}
};
return db.unscheduledIncident.update({deleted: true},{where: filters});
};
const insertUnlockedIncidents = (incidents) => {
const asyncJobs = [];
incidents.forEach((incident) => {
@@ -104,6 +115,16 @@ const insertUnlockedIncidents = (incidents) => {
return Promise.all(asyncJobs);
};
const deleteUnlockedIncidentsById = (incidentIds) => {
console.log('Delete unlocked in DB :', incidentIds);
const filters = {
id: {
[Op.in]: incidentIds
}
};
return db.unlockedIncident.update({deleted: true},{where: filters});
};
const setUnlockedIncidentsLevel = (incidents) => {
return new Promise ((resolve, reject) => {
const sortingFunction = (incidentA, incidentB) => {
@@ -576,5 +597,7 @@ const calculateDoorLockCharges = () => {
};
module.exports = {
calculateDoorLockCharges
calculateDoorLockCharges,
deleteUnlockedIncidentsById,
deleteUnscheduledIncidentsById
};