Fix for loading

This commit is contained in:
Senad Uka
2019-07-25 06:53:32 +02:00
parent a691ab94c7
commit 2db47e95e1
26 changed files with 838 additions and 400 deletions

View File

@@ -4,6 +4,7 @@ const { parseDoorLockDataFile, writeDoorLockEvent } = require('../services/doorL
const { fetchAllBookings, writeBookingReservation } = require('../services/officeRnD/bookings');
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
const { integrationServiceErrors } = require('../constants/constants');
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
const IncomingForm = require('formidable').IncomingForm;
@@ -42,11 +43,25 @@ const uploadDoorLockData = (req, res) => {
Promise.all(asyncWriteJobs)
.then(() => {
res.json({
parsedData,
parserErrors,
unknownMembers
});
checkBookingChanges()
.then(() => {
calculateDoorLockCharges()
.then(() => {
res.json({
parsedData,
parserErrors,
unknownMembers
});
})
.catch((error) => {
console.log('Error : ', error);
res.status(500).send(integrationServiceErrors.IMPORT_SUCCESSFUL_CALCULATION_FAILED);
});
})
.catch((error) => {
console.log('Error : ', error);
res.status(500).send(integrationServiceErrors.IMPORT_SUCCESSFUL_CALCULATION_FAILED);
});
})
.catch((error) => {
console.log(integrationServiceErrors.FAILED_TO_SAVE_DOOR_LOCK_ENTRIES);
@@ -54,7 +69,7 @@ const uploadDoorLockData = (req, res) => {
res.status(500).send(integrationServiceErrors.FAILED_TO_SAVE_DATA_GENERIC);
});
fetchAllBookings()
/*fetchAllBookings()
.then((bookingEntries) => {
const asyncJobs = [];
bookingEntries.forEach((bookingEntry) => asyncJobs.push(writeBookingReservation(bookingEntry)));
@@ -62,13 +77,18 @@ const uploadDoorLockData = (req, res) => {
Promise.all(asyncJobs)
.then(() => {
calculateDoorLockCharges();
});
})
.catch((error) => {
console.log('Error updating booking reservations : ');
console.log(error);
})
})
.catch((error) => {
console.log(integrationServiceErrors.FAILED_TO_SAVE_BOOKINGS);
console.log(error);
return;
});
*/
})
.catch((error) => {
res.status(500).send(error);

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);
})
@@ -65,9 +68,53 @@ const getMemberIncidents = (req, res) => {
});
};
const addFees = (req, res) => {
const memberIds = req.body && req.body.memberIds ? req.body.memberIds : [];
const dateRange = req.body && req.body.dateRange ? req.body.dateRange : {startDate: null, endDate: null};
const { startDate, endDate } = dateRange;
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');
}
};
module.exports = {
getKnownOfficeResourceMappings,
addNewMapping,
getAllIncidentsController,
getMemberIncidents,
addFees,
};