refactor function for getting all bookings to allow more filters
This commit is contained in:
@@ -48,9 +48,9 @@ const getActiveBookingsForMembersInDateRange = (dateRange, memberIds) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAllBookingsForYear = (year) => {
|
const getAllBookingsForMembersInDateRange = (dateRange, memberIds) => {
|
||||||
const startDate = moment.tz(year, 'YYYY', UI_TIMEZONE).startOf('year');
|
const startDate = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE).startOf('day');
|
||||||
const endDate = moment.tz(year, 'YYYY', UI_TIMEZONE).endOf('year');
|
const endDate = moment.tz(dateRange.endDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE).endOf('day');
|
||||||
|
|
||||||
const attributes = [
|
const attributes = [
|
||||||
'id',
|
'id',
|
||||||
@@ -76,6 +76,12 @@ const getAllBookingsForYear = (year) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (memberIds && Array.isArray(memberIds) && memberIds.length > 0){
|
||||||
|
filters.memberId = {
|
||||||
|
[Op.in]: memberIds
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return db.bookingReservation.findAll({
|
return db.bookingReservation.findAll({
|
||||||
attributes,
|
attributes,
|
||||||
where: filters,
|
where: filters,
|
||||||
@@ -84,5 +90,5 @@ const getAllBookingsForYear = (year) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getActiveBookingsForMembersInDateRange,
|
getActiveBookingsForMembersInDateRange,
|
||||||
getAllBookingsForYear,
|
getAllBookingsForMembersInDateRange,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const workbookCreator = require('excel4node');
|
|||||||
const { checkBookingChanges } = require('./checkBookingChange');
|
const { checkBookingChanges } = require('./checkBookingChange');
|
||||||
const { incidentType, UI_TIMEZONE, DEFAULT_DATE_FORMAT, integrationServiceErrors } = require('../../constants/constants');
|
const { incidentType, UI_TIMEZONE, DEFAULT_DATE_FORMAT, integrationServiceErrors } = require('../../constants/constants');
|
||||||
|
|
||||||
const { getAllBookingsForYear } = require('./bookings');
|
const { getAllBookingsForMembersInDateRange } = require('./bookings');
|
||||||
const { fetchAllMembers } = require('../officeRnD/members');
|
const { fetchAllMembers } = require('../officeRnD/members');
|
||||||
const { fetchOffices, fetchResources } = require('../officeRnD/resources');
|
const { fetchOffices, fetchResources } = require('../officeRnD/resources');
|
||||||
const { getChargedCanceledReservations } = require('../integration/bookingChangeCharges');
|
const { getChargedCanceledReservations } = require('../integration/bookingChangeCharges');
|
||||||
@@ -320,7 +320,15 @@ const getAllIncidents = (dateRange, memberIds) => {
|
|||||||
|
|
||||||
const getMemberPracticeSummaryReport = (year) => {
|
const getMemberPracticeSummaryReport = (year) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const asyncJobs = [checkBookingChanges(), getAllBookingsForYear(year), fetchAllMembers()];
|
|
||||||
|
const startDate = moment.tz(year, 'YYYY', UI_TIMEZONE).startOf('year').format(DEFAULT_DATE_FORMAT);
|
||||||
|
const endDate = moment.tz(year, 'YYYY', UI_TIMEZONE).endOf('year').format(DEFAULT_DATE_FORMAT);
|
||||||
|
const dateRange = {
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
};
|
||||||
|
|
||||||
|
const asyncJobs = [checkBookingChanges(), getAllBookingsForMembersInDateRange(dateRange), fetchAllMembers()];
|
||||||
|
|
||||||
Promise.all(asyncJobs)
|
Promise.all(asyncJobs)
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user