Fix for loading
This commit is contained in:
@@ -10,7 +10,7 @@ const { incidentType, UI_TIMEZONE, DEFAULT_DATE_FORMAT, integrationServiceErrors
|
||||
const { fetchAllMembers } = require('../officeRnD/members');
|
||||
const { fetchOffices, fetchResources } = require('../officeRnD/resources');
|
||||
|
||||
const getUnlockedIncidents = (startDate, endDate, memberId) => {
|
||||
const getUnlockedIncidents = (startDate, endDate, memberIds) => {
|
||||
const attributes = ['id', 'reservationId', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'unlockTimestamp', 'incidentLevel', 'incidentLevelPrice'];
|
||||
|
||||
const filters = {};
|
||||
@@ -41,8 +41,10 @@ const getUnlockedIncidents = (startDate, endDate, memberId) => {
|
||||
Object.assign(filters, bookingStartOrUnlockTimestamp);
|
||||
}
|
||||
|
||||
if (memberId){
|
||||
filters.memberId = memberId;
|
||||
if (memberIds.length > 0){
|
||||
filters.memberId = {
|
||||
[Op.in]: memberIds
|
||||
};
|
||||
}
|
||||
|
||||
return db.unlockedIncident.findAll({
|
||||
@@ -54,7 +56,7 @@ const getUnlockedIncidents = (startDate, endDate, memberId) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
const getUnscheduledIncidents = (startDate, endDate, memberIds) => {
|
||||
const attributes = [
|
||||
'id',
|
||||
'reservationId',
|
||||
@@ -98,8 +100,10 @@ const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
}
|
||||
|
||||
|
||||
if (memberId){
|
||||
filters.memberId = memberId;
|
||||
if (memberIds.length > 0){
|
||||
filters.memberId = {
|
||||
[Op.in]: memberIds
|
||||
};
|
||||
}
|
||||
|
||||
return db.unscheduledIncident.findAll({
|
||||
@@ -111,7 +115,7 @@ const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getBookingChangeIncidents = (startDate, endDate, memberId) => {
|
||||
const getBookingChangeIncidents = (startDate, endDate, memberIds) => {
|
||||
const attributes = [
|
||||
'id',
|
||||
'reservationId',
|
||||
@@ -138,8 +142,10 @@ const getBookingChangeIncidents = (startDate, endDate, memberId) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (memberId){
|
||||
filters.memberId = memberId;
|
||||
if (memberIds.length > 0){
|
||||
filters.memberId = {
|
||||
[Op.in]: memberIds
|
||||
};
|
||||
}
|
||||
|
||||
return db.bookingChangeIncident.findAll({
|
||||
@@ -160,7 +166,7 @@ const formatTime = (timestamp) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getAllIncidents = (dateRange, memberId) => {
|
||||
const getAllIncidents = (dateRange, memberIds) => {
|
||||
return new Promise ((resolve, reject) => {
|
||||
let startDate, endDate;
|
||||
|
||||
@@ -178,9 +184,9 @@ const getAllIncidents = (dateRange, memberId) => {
|
||||
fetchAllMembers(),
|
||||
fetchOffices(),
|
||||
fetchResources(),
|
||||
getUnlockedIncidents(startDate, endDate, memberId),
|
||||
getUnscheduledIncidents(startDate, endDate, memberId),
|
||||
getBookingChangeIncidents(startDate, endDate, memberId)
|
||||
getUnlockedIncidents(startDate, endDate, memberIds),
|
||||
getUnscheduledIncidents(startDate, endDate, memberIds),
|
||||
getBookingChangeIncidents(startDate, endDate, memberIds)
|
||||
];
|
||||
|
||||
Promise.all(dataFetchJobs)
|
||||
@@ -210,10 +216,14 @@ const getAllIncidents = (dateRange, memberId) => {
|
||||
memberId: unlockedIncident.memberId,
|
||||
memberName: membersMap[unlockedIncident.memberId].name,
|
||||
resourceName: resourcesMap[unlockedIncident.resourceId].resourceName,
|
||||
officeId: resourcesMap[unlockedIncident.resourceId].officeId,
|
||||
officeName: officesMap[resourcesMap[unlockedIncident.resourceId].officeId].officeName,
|
||||
bookingStart: formatTime(unlockedIncident.bookingStart),
|
||||
bookingEnd: formatTime(unlockedIncident.bookingEnd),
|
||||
bookingStartRaw: unlockedIncident.bookingStart,
|
||||
bookingEndRaw: unlockedIncident.bookingEnd,
|
||||
unlockTimestamp: formatTime(unlockedIncident.unlockTimestamp),
|
||||
unlockTimestampRaw: unlockedIncident.unlockTimestamp,
|
||||
incidentType: incidentTypeNumber,
|
||||
incidentLevel: unlockedIncident.incidentLevel,
|
||||
incidentPrice: unlockedIncident.incidentLevelPrice,
|
||||
@@ -236,11 +246,16 @@ const getAllIncidents = (dateRange, memberId) => {
|
||||
memberId: unscheduledIncident.memberId,
|
||||
memberName: membersMap[unscheduledIncident.memberId].name,
|
||||
resourceName: resourcesMap[unscheduledIncident.resourceId].resourceName,
|
||||
officeId: resourcesMap[unscheduledIncident.resourceId].officeId,
|
||||
officeName: officesMap[resourcesMap[unscheduledIncident.resourceId].officeId].officeName,
|
||||
bookingStart: formatTime(unscheduledIncident.bookingStart),
|
||||
bookingEnd: formatTime(unscheduledIncident.bookingEnd),
|
||||
bookingStartRaw: unscheduledIncident.bookingStart,
|
||||
bookingEndRaw: unscheduledIncident.bookingEnd,
|
||||
unlockTimestamp: formatTime(unscheduledIncident.unlockTimestamp),
|
||||
lockTimestamp: formatTime(unscheduledIncident.lockTimestamp),
|
||||
unlockTimestampRaw: unscheduledIncident.unlockTimestamp,
|
||||
lockTimestampRaw: unscheduledIncident.lockTimestamp,
|
||||
incidentType: incidentTypeNumber,
|
||||
timeIntervalsToCharge: unscheduledIncident.timeIntervalsToCharge,
|
||||
chargePrice: unscheduledIncident.chargePrice,
|
||||
@@ -267,21 +282,28 @@ const getAllIncidents = (dateRange, memberId) => {
|
||||
const newResource = newResourceId ? resourcesMap[newResourceId] : null;
|
||||
const oldResourceName = oldResource.resourceName;
|
||||
const newResourceName = newResource ? newResource.resourceName : null;
|
||||
const officeName = officesMap[oldResource.officeId].officeName;
|
||||
const officeId = oldResource.officeId;
|
||||
const officeName = officesMap[officeId].officeName;
|
||||
allIncidents.push({
|
||||
incidentId: id,
|
||||
memberId,
|
||||
memberName,
|
||||
oldResourceName,
|
||||
newResourceName,
|
||||
officeId,
|
||||
officeName,
|
||||
oldBookingStart: formatTime(oldBookingStart),
|
||||
oldBookingEnd: formatTime(oldBookingEnd),
|
||||
newBookingStart: formatTime(newBookingStart),
|
||||
newBookingEnd: formatTime(newBookingEnd),
|
||||
oldBookingStartRaw: oldBookingStart,
|
||||
oldBookingEndRaw: oldBookingEnd,
|
||||
newBookingStartRaw: newBookingStart,
|
||||
newBookingEndRaw: newBookingEnd,
|
||||
incidentType,
|
||||
totalChargeFee: chargeFee,
|
||||
incidentTimestamp: formatTime(createdAt),
|
||||
incidentTimestampRaw: createdAt,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -292,7 +314,5 @@ const getAllIncidents = (dateRange, memberId) => {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getUnlockedIncidents,
|
||||
getUnscheduledIncidents,
|
||||
getAllIncidents,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user