From 4775bff9b8862f74f1f18cffe93c6fb0eefa64da Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Mon, 22 Jul 2019 07:17:15 +0200 Subject: [PATCH] Fix for not showing incidents --- services/integration/doorLockCharges.js | 45 +++++++++++++++++++------ services/officeRnD/bookings.js | 2 +- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/services/integration/doorLockCharges.js b/services/integration/doorLockCharges.js index 59b1e81..0aeb222 100644 --- a/services/integration/doorLockCharges.js +++ b/services/integration/doorLockCharges.js @@ -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, }); } diff --git a/services/officeRnD/bookings.js b/services/officeRnD/bookings.js index 94549d1..2f18f0c 100644 --- a/services/officeRnD/bookings.js +++ b/services/officeRnD/bookings.js @@ -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'],