make dlock screen waiting for incident calculation to finish
This commit is contained in:
@@ -62,6 +62,7 @@ const officeRnDAPIErrors = {
|
|||||||
FAILED_TO_ADD_FEES: 'Failed to add fees in ORD',
|
FAILED_TO_ADD_FEES: 'Failed to add fees in ORD',
|
||||||
};
|
};
|
||||||
const integrationServiceErrors = {
|
const integrationServiceErrors = {
|
||||||
|
IMPORT_SUCCESSFUL_CALCULATION_FAILED: 'Import succeeded but fetching reservations and calculating charges failed',
|
||||||
FAILED_TO_SAVE_BOOKINGS: 'Failed to save booking reservations',
|
FAILED_TO_SAVE_BOOKINGS: 'Failed to save booking reservations',
|
||||||
FAILED_TO_SAVE_DOOR_LOCK_ENTRIES: 'Failed to save door lock entries',
|
FAILED_TO_SAVE_DOOR_LOCK_ENTRIES: 'Failed to save door lock entries',
|
||||||
FAILED_TO_SAVE_DATA_GENERIC: 'Failed to save data',
|
FAILED_TO_SAVE_DATA_GENERIC: 'Failed to save data',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const { parseDoorLockDataFile, writeDoorLockEvent } = require('../services/doorL
|
|||||||
const { fetchAllBookings, writeBookingReservation } = require('../services/officeRnD/bookings');
|
const { fetchAllBookings, writeBookingReservation } = require('../services/officeRnD/bookings');
|
||||||
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
||||||
const { integrationServiceErrors } = require('../constants/constants');
|
const { integrationServiceErrors } = require('../constants/constants');
|
||||||
|
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
||||||
|
|
||||||
const IncomingForm = require('formidable').IncomingForm;
|
const IncomingForm = require('formidable').IncomingForm;
|
||||||
|
|
||||||
@@ -41,6 +42,10 @@ const uploadDoorLockData = (req, res) => {
|
|||||||
parsedData.forEach((entry) => asyncWriteJobs.push(writeDoorLockEvent(entry)));
|
parsedData.forEach((entry) => asyncWriteJobs.push(writeDoorLockEvent(entry)));
|
||||||
|
|
||||||
Promise.all(asyncWriteJobs)
|
Promise.all(asyncWriteJobs)
|
||||||
|
.then(() => {
|
||||||
|
checkBookingChanges()
|
||||||
|
.then(() => {
|
||||||
|
calculateDoorLockCharges()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.json({
|
res.json({
|
||||||
parsedData,
|
parsedData,
|
||||||
@@ -48,13 +53,23 @@ const uploadDoorLockData = (req, res) => {
|
|||||||
unknownMembers
|
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) => {
|
.catch((error) => {
|
||||||
console.log(integrationServiceErrors.FAILED_TO_SAVE_DOOR_LOCK_ENTRIES);
|
console.log(integrationServiceErrors.FAILED_TO_SAVE_DOOR_LOCK_ENTRIES);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
res.status(500).send(integrationServiceErrors.FAILED_TO_SAVE_DATA_GENERIC);
|
res.status(500).send(integrationServiceErrors.FAILED_TO_SAVE_DATA_GENERIC);
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchAllBookings()
|
/*fetchAllBookings()
|
||||||
.then((bookingEntries) => {
|
.then((bookingEntries) => {
|
||||||
const asyncJobs = [];
|
const asyncJobs = [];
|
||||||
bookingEntries.forEach((bookingEntry) => asyncJobs.push(writeBookingReservation(bookingEntry)));
|
bookingEntries.forEach((bookingEntry) => asyncJobs.push(writeBookingReservation(bookingEntry)));
|
||||||
@@ -62,13 +77,18 @@ const uploadDoorLockData = (req, res) => {
|
|||||||
Promise.all(asyncJobs)
|
Promise.all(asyncJobs)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
calculateDoorLockCharges();
|
calculateDoorLockCharges();
|
||||||
});
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error updating booking reservations : ');
|
||||||
|
console.log(error);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(integrationServiceErrors.FAILED_TO_SAVE_BOOKINGS);
|
console.log(integrationServiceErrors.FAILED_TO_SAVE_BOOKINGS);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
|
|||||||
@@ -510,6 +510,7 @@ const getIncidentData = (reservation) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const calculateDoorLockCharges = () => {
|
const calculateDoorLockCharges = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
getAllFinishedBookings()
|
getAllFinishedBookings()
|
||||||
.then((reservations) => {
|
.then((reservations) => {
|
||||||
const unlockedIncidents = [];
|
const unlockedIncidents = [];
|
||||||
@@ -543,19 +544,32 @@ const calculateDoorLockCharges = () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setUnlockedIncidentsLevel(unlockedIncidents)
|
||||||
|
.then((completedUnlockedIncidents) => {
|
||||||
|
const insertIncidentsJobs = [insertUnscheduledIncidents(unscheduledIncidents), insertUnlockedIncidents(completedUnlockedIncidents)];
|
||||||
|
|
||||||
|
Promise.all(insertIncidentsJobs)
|
||||||
|
.then(() => {
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
insertUnscheduledIncidents(unscheduledIncidents)
|
insertUnscheduledIncidents(unscheduledIncidents)
|
||||||
.catch((error) => console.log(error));
|
.catch((error) => console.log(error));
|
||||||
|
|
||||||
setUnlockedIncidentsLevel(unlockedIncidents)
|
|
||||||
.then((completedUnlockedIncidents) => {
|
|
||||||
insertUnlockedIncidents(completedUnlockedIncidents)
|
insertUnlockedIncidents(completedUnlockedIncidents)
|
||||||
.catch((error) => console.log(error));
|
.catch((error) => console.log(error));
|
||||||
|
*/
|
||||||
})
|
})
|
||||||
.catch((error) => console.log(error));
|
.catch((error) => reject(error));
|
||||||
})
|
})
|
||||||
.catch((error) => console.log(error));
|
.catch((error) => reject(error));
|
||||||
})
|
})
|
||||||
.catch((error) => console.log(error));
|
.catch((error) => reject(error));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in New Issue
Block a user