invoice integration

This commit is contained in:
Bilal Catic
2019-07-25 02:00:27 +02:00
parent aeffe86313
commit 71e034b6c2
12 changed files with 548 additions and 65 deletions

View File

@@ -2,6 +2,9 @@
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase } = require('../services/officeRnD/resources');
const { getAllIncidents } = require('../services/integration/reports');
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
const getKnownOfficeResourceMappings = (req, res) => {
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources() ];
@@ -38,7 +41,7 @@ const getAllIncidentsController = (req, res) => {
endDate: req.params.endDate,
};
getAllIncidents(dateRange)
getAllIncidents(dateRange, [])
.then((incidents) => {
res.send(incidents);
})
@@ -55,7 +58,7 @@ const getMemberIncidents = (req, res) => {
endDate: req.params.endDate,
};
getAllIncidents(dateRange, memberId)
getAllIncidents(dateRange, [memberId])
.then((incidents) => {
res.send(incidents);
})
@@ -70,8 +73,39 @@ const addFees = (req, res) => {
const dateRange = req.body && req.body.dateRange ? req.body.dateRange : {startDate: null, endDate: null};
const { startDate, endDate } = dateRange;
if (startDate && endDate){
res.send();
if (startDate && endDate && Array.isArray(memberIds)){
checkBookingChanges()
.then(() => {
deleteFeesFromORD(dateRange, memberIds)
.then(() => {
// TODO: Change this to parallel execution
getMembersFeesForDateRange(dateRange, memberIds)
.then((allFees) => {
addFeesToORD(allFees)
.then((numberOfInsertedFees) => {
res.send({
status: 'ok',
numberOfInsertedFees
});
})
.catch((error) => {
console.log('Error adding fees');
res.status(500).send(error);
})
})
.catch((error) => {
console.log(error);
res.status(500).send(error);
})
})
.catch((error) => {
res.status(500).send(error);
});
})
.catch((error) => {
console.log('Error with updating booking reservations');
res.status(500).send(error);
})
}else{
res.status(400).send('Date range is missing');
}