Fixed column names and the report
This commit is contained in:
@@ -11,17 +11,34 @@ const { fetchAllMembers } = require('../officeRnD/members');
|
||||
const { fetchOffices, fetchResources } = require('../officeRnD/resources');
|
||||
|
||||
const getUnlockedIncidents = (startDate, endDate, memberId) => {
|
||||
const attributes = ['id', '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){
|
||||
@@ -40,12 +57,13 @@ const getUnlockedIncidents = (startDate, endDate, memberId) => {
|
||||
const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
const attributes = [
|
||||
'id',
|
||||
'reservationId',
|
||||
'memberId',
|
||||
'resourceId',
|
||||
'bookingStart',
|
||||
'bookingEnd',
|
||||
'doorLockEventTimestamp',
|
||||
'doorLockEventType',
|
||||
'unlockTimestamp',
|
||||
'lockTimestamp',
|
||||
'timeIntervalsToCharge',
|
||||
'chargePrice',
|
||||
'totalChargeFee'
|
||||
@@ -54,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;
|
||||
}
|
||||
@@ -76,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) => {
|
||||
@@ -114,6 +155,8 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
const allIncidents = [];
|
||||
|
||||
unlockedIncidents.forEach((unlockedIncident) => {
|
||||
const incidentTypeNumber = unlockedIncident.reservationId ?
|
||||
incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION : incidentType.UNLOCKED_INCIDENT_STANDALONE;
|
||||
allIncidents.push({
|
||||
incidentId: unlockedIncident.id,
|
||||
memberId: unlockedIncident.memberId,
|
||||
@@ -122,13 +165,24 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
officeName: officesMap[resourcesMap[unlockedIncident.resourceId].officeId].officeName,
|
||||
bookingStart: formatTime(unlockedIncident.bookingStart),
|
||||
bookingEnd: formatTime(unlockedIncident.bookingEnd),
|
||||
incidentType: incidentType.UNLOCKED_INCIDENT,
|
||||
unlockTimestamp: formatTime(unlockedIncident.unlockTimestamp),
|
||||
incidentType: incidentTypeNumber,
|
||||
incidentLevel: unlockedIncident.incidentLevel,
|
||||
incidentPrice: unlockedIncident.incidentLevelPrice,
|
||||
});
|
||||
});
|
||||
|
||||
unscheduledIncidents.forEach((unscheduledIncident) => {
|
||||
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,
|
||||
@@ -137,7 +191,9 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
officeName: officesMap[resourcesMap[unscheduledIncident.resourceId].officeId].officeName,
|
||||
bookingStart: formatTime(unscheduledIncident.bookingStart),
|
||||
bookingEnd: formatTime(unscheduledIncident.bookingEnd),
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT,
|
||||
unlockTimestamp: formatTime(unscheduledIncident.unlockTimestamp),
|
||||
lockTimestamp: formatTime(unscheduledIncident.lockTimestamp),
|
||||
incidentType: incidentTypeNumber,
|
||||
timeIntervalsToCharge: unscheduledIncident.timeIntervalsToCharge,
|
||||
chargePrice: unscheduledIncident.chargePrice,
|
||||
totalChargeFee: unscheduledIncident.totalChargeFee,
|
||||
|
||||
Reference in New Issue
Block a user