Fix for not showing incidents
This commit is contained in:
@@ -3,7 +3,15 @@
|
||||
const moment = require('moment-timezone');
|
||||
const db = require('../../models/index');
|
||||
|
||||
const { doorLockEvents, incidentType, unlockedIncidentLevelsPrices, UNSCHEDULED_CHARGE_PRICE, MAX_BACK_TO_BACK_DIFFERENCE, UNSCHEDULED_TIME_RESOLUTION } = require('../../constants/constants');
|
||||
const {
|
||||
doorLockEvents,
|
||||
incidentType,
|
||||
unlockedIncidentLevelsPrices,
|
||||
UNSCHEDULED_CHARGE_PRICE,
|
||||
MAX_BACK_TO_BACK_DIFFERENCE,
|
||||
UNSCHEDULED_TIME_RESOLUTION,
|
||||
UI_TIMEZONE
|
||||
} = require('../../constants/constants');
|
||||
const { getUnlockEntryForReservation, getLockEntryForReservation, getEntriesBetween, getLastEntryForReservation } = require('../doorLock/doorLock');
|
||||
const { getAllFinishedBookings, getFirstPreviousBooking, getFirstNextBooking } = require('../officeRnD/bookings');
|
||||
|
||||
@@ -360,20 +368,37 @@ const getIncidentData = (reservation) => {
|
||||
};
|
||||
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
|
||||
const lockMoment = moment.utc(pairLockEntry.timestamp);
|
||||
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
||||
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
||||
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
||||
if (timeIntervalsToCharge > 0){
|
||||
|
||||
if (lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day')){
|
||||
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
||||
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
||||
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
||||
if (timeIntervalsToCharge > 0){
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
||||
reservation: emptyReservation,
|
||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||
lockTimestamp: pairLockEntry.timestamp,
|
||||
memberId: pairUnlockEntry.memberId,
|
||||
resourceId,
|
||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||
timeIntervalsToCharge,
|
||||
totalChargeFee,
|
||||
});
|
||||
}
|
||||
}else{
|
||||
const emptyReservation = {
|
||||
reservationId: null,
|
||||
start: null,
|
||||
end: null,
|
||||
};
|
||||
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||
reservation: emptyReservation,
|
||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||
lockTimestamp: pairLockEntry.timestamp,
|
||||
memberId: pairUnlockEntry.memberId,
|
||||
resourceId,
|
||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||
timeIntervalsToCharge,
|
||||
totalChargeFee,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ const fetchAllBookings = () => {
|
||||
bookingData.forEach((fullBookingEntry) => {
|
||||
const fees = fullBookingEntry && fullBookingEntry.fees ? fullBookingEntry.fees : [];
|
||||
const firstFee = fees.length > 0 && fees[0].fee ? fees[0].fee : undefined;
|
||||
const hourlyRate = firstFee && firstFee.price ? firstFee.price : undefined;
|
||||
const hourlyRate = firstFee && firstFee.price ? firstFee.price : 0;
|
||||
|
||||
cleanedBookingReservations.push({
|
||||
reservationId: fullBookingEntry['_id'],
|
||||
|
||||
Reference in New Issue
Block a user