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

@@ -510,52 +510,66 @@ const getIncidentData = (reservation) => {
};
const calculateDoorLockCharges = () => {
getAllFinishedBookings()
.then((reservations) => {
const unlockedIncidents = [];
const unscheduledIncidents = [];
return new Promise((resolve, reject) => {
getAllFinishedBookings()
.then((reservations) => {
const unlockedIncidents = [];
const unscheduledIncidents = [];
const asyncCheckForIncidents = [];
const asyncCheckForIncidents = [];
reservations.forEach((reservation) => {
asyncCheckForIncidents.push(getIncidentData(reservation));
});
reservations.forEach((reservation) => {
asyncCheckForIncidents.push(getIncidentData(reservation));
});
Promise.all(asyncCheckForIncidents)
.then((allReservationsIncidents) => {
allReservationsIncidents.forEach((reservationIncidents) => {
reservationIncidents.forEach((incident) => {
if (incident.error) {
console.log('Error checking incident : ', incident.error);
} else if (incident.incidentType) {
switch (incident.incidentType) {
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
unlockedIncidents.push(incident);
break;
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
unscheduledIncidents.push(incident);
break;
Promise.all(asyncCheckForIncidents)
.then((allReservationsIncidents) => {
allReservationsIncidents.forEach((reservationIncidents) => {
reservationIncidents.forEach((incident) => {
if (incident.error) {
console.log('Error checking incident : ', incident.error);
} else if (incident.incidentType) {
switch (incident.incidentType) {
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
unlockedIncidents.push(incident);
break;
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
unscheduledIncidents.push(incident);
break;
}
}
}
});
});
});
insertUnscheduledIncidents(unscheduledIncidents)
.catch((error) => console.log(error));
setUnlockedIncidentsLevel(unlockedIncidents)
.then((completedUnlockedIncidents) => {
const insertIncidentsJobs = [insertUnscheduledIncidents(unscheduledIncidents), insertUnlockedIncidents(completedUnlockedIncidents)];
setUnlockedIncidentsLevel(unlockedIncidents)
.then((completedUnlockedIncidents) => {
insertUnlockedIncidents(completedUnlockedIncidents)
.catch((error) => console.log(error));
})
.catch((error) => console.log(error));
})
.catch((error) => console.log(error));
})
.catch((error) => console.log(error));
Promise.all(insertIncidentsJobs)
.then(() => {
resolve(true);
})
.catch((error) => {
reject(error);
});
/*
insertUnscheduledIncidents(unscheduledIncidents)
.catch((error) => console.log(error));
insertUnlockedIncidents(completedUnlockedIncidents)
.catch((error) => console.log(error));
*/
})
.catch((error) => reject(error));
})
.catch((error) => reject(error));
})
.catch((error) => reject(error));
});
};
module.exports = {