make difference between pre-reservation and post-reservation unscheduled use
This commit is contained in:
@@ -62,9 +62,10 @@ const integrationServiceErrors = {
|
||||
const incidentType = {
|
||||
NOT_AN_INCIDENT: 1,
|
||||
UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION: 2,
|
||||
UNSCHEDULED_INCIDENT_RELATED_WITH_RESERVATION: 3,
|
||||
UNLOCKED_INCIDENT_STANDALONE: 4,
|
||||
UNSCHEDULED_INCIDENT_STANDALONE: 5,
|
||||
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION: 3,
|
||||
UNSCHEDULED_INCIDENT_AFTER_RESERVATION: 4,
|
||||
UNLOCKED_INCIDENT_STANDALONE: 5,
|
||||
UNSCHEDULED_INCIDENT_STANDALONE: 6,
|
||||
};
|
||||
|
||||
const UI_TIMEZONE = process.env.UI_TIMEZONE || 'America/Los_Angeles';
|
||||
|
||||
@@ -400,7 +400,7 @@ const getIncidentData = (reservation) => {
|
||||
// 1. Check if member entered before reservation start time
|
||||
if (unlockEntry && chargeBefore && !previousReservationIsBackToBack) {
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_RELATED_WITH_RESERVATION,
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
|
||||
reservation,
|
||||
unlockTimestamp: unlockEntry.timestamp,
|
||||
lockTimestamp: null,
|
||||
@@ -415,7 +415,7 @@ const getIncidentData = (reservation) => {
|
||||
// 2. Check if member left after reservation end time
|
||||
if (lockEntry && chargeAfter && !nextReservationIsBackToBack) {
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_RELATED_WITH_RESERVATION,
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
|
||||
reservation,
|
||||
unlockTimestamp: null,
|
||||
lockTimestamp: lockEntry.timestamp,
|
||||
@@ -508,7 +508,8 @@ const calculateDoorLockCharges = () => {
|
||||
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
|
||||
unlockedIncidents.push(incident);
|
||||
break;
|
||||
case incidentType.UNSCHEDULED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
|
||||
unscheduledIncidents.push(incident);
|
||||
break;
|
||||
|
||||
@@ -11,17 +11,34 @@ const { fetchAllMembers } = require('../officeRnD/members');
|
||||
const { fetchOffices, fetchResources } = require('../officeRnD/resources');
|
||||
|
||||
const getUnlockedIncidents = (startDate, endDate, memberId) => {
|
||||
const attributes = ['id', 'reservationId', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'incidentLevel', 'incidentLevelPrice'];
|
||||
const attributes = ['id', 'reservationId', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'unlockTimestamp', 'incidentLevel', 'incidentLevelPrice'];
|
||||
|
||||
const filters = {};
|
||||
|
||||
if (startDate && endDate) {
|
||||
filters.bookingStart = {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.utc().toISOString(),
|
||||
[Op.lte]: endDate.utc().toISOString(),
|
||||
const bookingStartCondition = {
|
||||
bookingStart: {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.toISOString(),
|
||||
[Op.lte]: endDate.toISOString(),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const unlockTimestampCondition = {
|
||||
unlockTimestamp: {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.toISOString(),
|
||||
[Op.lte]: endDate.toISOString(),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const bookingStartOrUnlockTimestamp = {
|
||||
[Op.or]: [bookingStartCondition, unlockTimestampCondition]
|
||||
};
|
||||
|
||||
Object.assign(filters, bookingStartOrUnlockTimestamp);
|
||||
}
|
||||
|
||||
if (memberId){
|
||||
@@ -45,8 +62,8 @@ const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
'resourceId',
|
||||
'bookingStart',
|
||||
'bookingEnd',
|
||||
'doorLockEventTimestamp',
|
||||
'doorLockEventType',
|
||||
'unlockTimestamp',
|
||||
'lockTimestamp',
|
||||
'timeIntervalsToCharge',
|
||||
'chargePrice',
|
||||
'totalChargeFee'
|
||||
@@ -55,14 +72,32 @@ const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
const filters = {};
|
||||
|
||||
if (startDate && endDate) {
|
||||
filters.bookingStart = {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.utc().toISOString(),
|
||||
[Op.lte]: endDate.utc().toISOString(),
|
||||
const bookingStartCondition = {
|
||||
bookingStart: {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.toISOString(),
|
||||
[Op.lte]: endDate.toISOString(),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const unlockTimestampCondition = {
|
||||
unlockTimestamp: {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.toISOString(),
|
||||
[Op.lte]: endDate.toISOString(),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const bookingStartOrUnlockTimestamp = {
|
||||
[Op.or]: [bookingStartCondition, unlockTimestampCondition]
|
||||
};
|
||||
|
||||
Object.assign(filters, bookingStartOrUnlockTimestamp);
|
||||
}
|
||||
|
||||
|
||||
if (memberId){
|
||||
filters.memberId = memberId;
|
||||
}
|
||||
@@ -77,7 +112,12 @@ const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
};
|
||||
|
||||
const formatTime = (timestamp) => {
|
||||
return moment.tz(timestamp, UI_TIMEZONE).format('MM/DD/YYYY hh:mm a');
|
||||
const momentObject = moment.tz(timestamp, UI_TIMEZONE);
|
||||
if (momentObject.isValid()){
|
||||
return momentObject.format('MM/DD/YYYY hh:mm a');
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
@@ -115,7 +155,7 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
const allIncidents = [];
|
||||
|
||||
unlockedIncidents.forEach((unlockedIncident) => {
|
||||
const incidentTypeNumber = unlockedIncident.reservationId.length > 0 ?
|
||||
const incidentTypeNumber = unlockedIncident.reservationId ?
|
||||
incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION : incidentType.UNLOCKED_INCIDENT_STANDALONE;
|
||||
allIncidents.push({
|
||||
incidentId: unlockedIncident.id,
|
||||
@@ -125,6 +165,7 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
officeName: officesMap[resourcesMap[unlockedIncident.resourceId].officeId].officeName,
|
||||
bookingStart: formatTime(unlockedIncident.bookingStart),
|
||||
bookingEnd: formatTime(unlockedIncident.bookingEnd),
|
||||
unlockTimestamp: formatTime(unlockedIncident.unlockTimestamp),
|
||||
incidentType: incidentTypeNumber,
|
||||
incidentLevel: unlockedIncident.incidentLevel,
|
||||
incidentPrice: unlockedIncident.incidentLevelPrice,
|
||||
@@ -132,8 +173,16 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
});
|
||||
|
||||
unscheduledIncidents.forEach((unscheduledIncident) => {
|
||||
const incidentTypeNumber = unscheduledIncident.reservationId.length > 0 ?
|
||||
incidentType.UNSCHEDULED_INCIDENT_RELATED_WITH_RESERVATION : incidentType.UNSCHEDULED_INCIDENT_STANDALONE;
|
||||
let incidentTypeNumber;
|
||||
if (unscheduledIncident.reservationId){
|
||||
if (unscheduledIncident.unlockTimestamp && !unscheduledIncident.lockTimestamp){
|
||||
incidentTypeNumber = incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION;
|
||||
}else{
|
||||
incidentTypeNumber = incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION;
|
||||
}
|
||||
}else{
|
||||
incidentTypeNumber = incidentType.UNSCHEDULED_INCIDENT_STANDALONE;
|
||||
}
|
||||
allIncidents.push({
|
||||
incidentId: unscheduledIncident.id,
|
||||
memberId: unscheduledIncident.memberId,
|
||||
@@ -142,6 +191,8 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
officeName: officesMap[resourcesMap[unscheduledIncident.resourceId].officeId].officeName,
|
||||
bookingStart: formatTime(unscheduledIncident.bookingStart),
|
||||
bookingEnd: formatTime(unscheduledIncident.bookingEnd),
|
||||
unlockTimestamp: formatTime(unscheduledIncident.unlockTimestamp),
|
||||
lockTimestamp: formatTime(unscheduledIncident.lockTimestamp),
|
||||
incidentType: incidentTypeNumber,
|
||||
timeIntervalsToCharge: unscheduledIncident.timeIntervalsToCharge,
|
||||
chargePrice: unscheduledIncident.chargePrice,
|
||||
|
||||
Reference in New Issue
Block a user