handle fetching members list and members incidents list
This commit is contained in:
@@ -10,17 +10,23 @@ const { incidentType, UI_TIMEZONE, DEFAULT_DATE_FORMAT, integrationServiceErrors
|
||||
const { fetchAllMembers } = require('../officeRnD/members');
|
||||
const { fetchOffices, fetchResources } = require('../officeRnD/resources');
|
||||
|
||||
const getUnlockedIncidents = (startDate, endDate) => {
|
||||
const getUnlockedIncidents = (startDate, endDate, memberId) => {
|
||||
const attributes = ['id', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'incidentLevel', 'incidentLevelPrice'];
|
||||
|
||||
const filters = (startDate && endDate) ? {
|
||||
bookingStart: {
|
||||
const filters = {};
|
||||
|
||||
if (startDate && endDate) {
|
||||
filters.bookingStart = {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.utc().toISOString(),
|
||||
[Op.lte]: endDate.utc().toISOString(),
|
||||
}
|
||||
},
|
||||
} : null;
|
||||
}
|
||||
}
|
||||
|
||||
if (memberId){
|
||||
filters.memberId = memberId;
|
||||
}
|
||||
|
||||
return db.unlockedIncident.findAll({
|
||||
attributes,
|
||||
@@ -31,7 +37,7 @@ const getUnlockedIncidents = (startDate, endDate) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getUnscheduledIncidents = (startDate, endDate) => {
|
||||
const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
const attributes = [
|
||||
'id',
|
||||
'memberId',
|
||||
@@ -45,14 +51,20 @@ const getUnscheduledIncidents = (startDate, endDate) => {
|
||||
'totalChargeFee'
|
||||
];
|
||||
|
||||
const filters = (startDate && endDate) ? {
|
||||
bookingStart: {
|
||||
const filters = {};
|
||||
|
||||
if (startDate && endDate) {
|
||||
filters.bookingStart = {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.utc().toISOString(),
|
||||
[Op.lte]: endDate.utc().toISOString(),
|
||||
}
|
||||
},
|
||||
} : null;
|
||||
}
|
||||
}
|
||||
|
||||
if (memberId){
|
||||
filters.memberId = memberId;
|
||||
}
|
||||
|
||||
return db.unscheduledIncident.findAll({
|
||||
attributes,
|
||||
@@ -67,7 +79,7 @@ const formatTime = (timestamp) => {
|
||||
return moment.tz(timestamp, UI_TIMEZONE).format('MM/DD/YYYY hh:mm a');
|
||||
};
|
||||
|
||||
const getAllDoorLockIncidents = (dateRange) => {
|
||||
const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
return new Promise ((resolve, reject) => {
|
||||
let startDate, endDate;
|
||||
|
||||
@@ -81,7 +93,7 @@ const getAllDoorLockIncidents = (dateRange) => {
|
||||
}
|
||||
}
|
||||
|
||||
const dataFetchJobs = [fetchAllMembers(), fetchOffices(), fetchResources(), getUnlockedIncidents(startDate, endDate), getUnscheduledIncidents(startDate, endDate)];
|
||||
const dataFetchJobs = [fetchAllMembers(), fetchOffices(), fetchResources(), getUnlockedIncidents(startDate, endDate, memberId), getUnscheduledIncidents(startDate, endDate, memberId)];
|
||||
|
||||
Promise.all(dataFetchJobs)
|
||||
.then((data) => {
|
||||
|
||||
Reference in New Issue
Block a user