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