Merge branch 'fix-incidents-for-bookings-with-break-between' into 'master'
Fix incidents for bookings with break between See merge request saburly/psihologija!74
This commit was merged in pull request #74.
This commit is contained in:
@@ -177,8 +177,8 @@ const setUnlockedIncidentsLevel = (incidents) => {
|
|||||||
formattedIncident.incidentLevel = unlockedIncidentLevelsPrices.UNLOCKED_0.title;
|
formattedIncident.incidentLevel = unlockedIncidentLevelsPrices.UNLOCKED_0.title;
|
||||||
formattedIncident.incidentLevelPrice = unlockedIncidentLevelsPrices.UNLOCKED_0.price;
|
formattedIncident.incidentLevelPrice = unlockedIncidentLevelsPrices.UNLOCKED_0.price;
|
||||||
} else {
|
} else {
|
||||||
const lastIncidentTime = moment.utc(memberLastIncident.incidentTimestamp).startOf('month');
|
const lastIncidentTime = moment.tz(memberLastIncident.incidentTimestamp, UI_TIMEZONE).startOf('month');
|
||||||
const currentIncidentTime = moment.utc(incident.unlockTimestamp).startOf('month');
|
const currentIncidentTime = moment.tz(incident.unlockTimestamp, UI_TIMEZONE).startOf('month');
|
||||||
const timeDiff = Math.abs(lastIncidentTime.diff(currentIncidentTime, 'months'));
|
const timeDiff = Math.abs(lastIncidentTime.diff(currentIncidentTime, 'months'));
|
||||||
|
|
||||||
if (timeDiff >= (parseInt(process.env.UNLOCK_STREAK_REPAIR_AFTER) || 6)){
|
if (timeDiff >= (parseInt(process.env.UNLOCK_STREAK_REPAIR_AFTER) || 6)){
|
||||||
@@ -405,6 +405,12 @@ const getIncidentData = (reservation) => {
|
|||||||
|
|
||||||
//**********************
|
//**********************
|
||||||
|
|
||||||
|
const emptyReservation = {
|
||||||
|
reservationId: null,
|
||||||
|
start: null,
|
||||||
|
end: null,
|
||||||
|
};
|
||||||
|
|
||||||
// 1. Check if member entered before reservation start time
|
// 1. Check if member entered before reservation start time
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||||
// console.log('\r\n\r\nChecking if member entered before reservation start time :');
|
// console.log('\r\n\r\nChecking if member entered before reservation start time :');
|
||||||
@@ -471,12 +477,6 @@ const getIncidentData = (reservation) => {
|
|||||||
// }
|
// }
|
||||||
let forgotToLockAsyncCheck;
|
let forgotToLockAsyncCheck;
|
||||||
if (!lockEntry && !nextReservationIsBackToBack){
|
if (!lockEntry && !nextReservationIsBackToBack){
|
||||||
const emptyReservation = {
|
|
||||||
reservationId: null,
|
|
||||||
start: null,
|
|
||||||
end: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (unlockEntry){
|
if (unlockEntry){
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||||
// console.log('\tIncident : YES [#1]');
|
// console.log('\tIncident : YES [#1]');
|
||||||
@@ -538,6 +538,38 @@ const getIncidentData = (reservation) => {
|
|||||||
|
|
||||||
if (previousReservationResults){
|
if (previousReservationResults){
|
||||||
const previousReservationLockEntry = previousReservationResults.lockEntry;
|
const previousReservationLockEntry = previousReservationResults.lockEntry;
|
||||||
|
const previousReservationUnlockEntry = previousReservationResults.unlockEntry;
|
||||||
|
|
||||||
|
//Special check for bookings with break between
|
||||||
|
if (previousReservation &&
|
||||||
|
!previousReservationIsBackToBack &&
|
||||||
|
previousReservation.memberId === currentReservation.memberId &&
|
||||||
|
previousReservationUnlockEntry && !previousReservationLockEntry &&
|
||||||
|
!unlockEntry && lockEntry //current reservation unlock / lock entries
|
||||||
|
) {
|
||||||
|
|
||||||
|
const unlockMoment = previousReservation.end ? moment.utc(previousReservation.end) : null;
|
||||||
|
const lockMoment = currentReservation.start ? moment.utc(currentReservation.start) : null;
|
||||||
|
|
||||||
|
if (unlockMoment && lockMoment){
|
||||||
|
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: previousReservation.end,
|
||||||
|
lockTimestamp: currentReservation.start,
|
||||||
|
memberId: currentReservation.memberId,
|
||||||
|
resourceId,
|
||||||
|
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||||
|
timeIntervalsToCharge,
|
||||||
|
totalChargeFee,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fromTimestamp = previousReservationLockEntry && previousReservationLockEntry.timestamp ?
|
fromTimestamp = previousReservationLockEntry && previousReservationLockEntry.timestamp ?
|
||||||
previousReservationLockEntry.timestamp : previousReservation.end;
|
previousReservationLockEntry.timestamp : previousReservation.end;
|
||||||
@@ -599,12 +631,6 @@ const getIncidentData = (reservation) => {
|
|||||||
if (!pairUnlockEntry){
|
if (!pairUnlockEntry){
|
||||||
pairUnlockEntry = entry;
|
pairUnlockEntry = entry;
|
||||||
}else{
|
}else{
|
||||||
const emptyReservation = {
|
|
||||||
reservationId: null,
|
|
||||||
start: null,
|
|
||||||
end: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
incidents.push({
|
incidents.push({
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||||
reservation: emptyReservation,
|
reservation: emptyReservation,
|
||||||
@@ -620,11 +646,7 @@ const getIncidentData = (reservation) => {
|
|||||||
case doorLockEvents.USER_LOCKED:
|
case doorLockEvents.USER_LOCKED:
|
||||||
if (pairUnlockEntry && !pairLockEntry){
|
if (pairUnlockEntry && !pairLockEntry){
|
||||||
pairLockEntry = entry;
|
pairLockEntry = entry;
|
||||||
const emptyReservation = {
|
|
||||||
reservationId: null,
|
|
||||||
start: null,
|
|
||||||
end: null,
|
|
||||||
};
|
|
||||||
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
|
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
|
||||||
const lockMoment = moment.utc(pairLockEntry.timestamp);
|
const lockMoment = moment.utc(pairLockEntry.timestamp);
|
||||||
|
|
||||||
@@ -646,12 +668,6 @@ const getIncidentData = (reservation) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
const emptyReservation = {
|
|
||||||
reservationId: null,
|
|
||||||
start: null,
|
|
||||||
end: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
incidents.push({
|
incidents.push({
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||||
reservation: emptyReservation,
|
reservation: emptyReservation,
|
||||||
@@ -676,12 +692,6 @@ const getIncidentData = (reservation) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (pairUnlockEntry){
|
if (pairUnlockEntry){
|
||||||
const emptyReservation = {
|
|
||||||
reservationId: null,
|
|
||||||
start: null,
|
|
||||||
end: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
incidents.push({
|
incidents.push({
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||||
reservation: emptyReservation,
|
reservation: emptyReservation,
|
||||||
|
|||||||
Reference in New Issue
Block a user