diff --git a/services/integration/bookings.js b/services/integration/bookings.js index 28ddec8..e672a73 100644 --- a/services/integration/bookings.js +++ b/services/integration/bookings.js @@ -48,9 +48,9 @@ const getActiveBookingsForMembersInDateRange = (dateRange, memberIds) => { }); }; -const getAllBookingsForYear = (year) => { - const startDate = moment.tz(year, 'YYYY', UI_TIMEZONE).startOf('year'); - const endDate = moment.tz(year, 'YYYY', UI_TIMEZONE).endOf('year'); +const getAllBookingsForMembersInDateRange = (dateRange, memberIds) => { + const startDate = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE).startOf('day'); + const endDate = moment.tz(dateRange.endDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE).endOf('day'); const attributes = [ '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({ attributes, where: filters, @@ -84,5 +90,5 @@ const getAllBookingsForYear = (year) => { module.exports = { getActiveBookingsForMembersInDateRange, - getAllBookingsForYear, + getAllBookingsForMembersInDateRange, }; diff --git a/services/integration/reports.js b/services/integration/reports.js index 8633f4b..ae79c34 100644 --- a/services/integration/reports.js +++ b/services/integration/reports.js @@ -10,7 +10,7 @@ const workbookCreator = require('excel4node'); const { checkBookingChanges } = require('./checkBookingChange'); 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 { fetchOffices, fetchResources } = require('../officeRnD/resources'); const { getChargedCanceledReservations } = require('../integration/bookingChangeCharges'); @@ -320,7 +320,15 @@ const getAllIncidents = (dateRange, memberIds) => { const getMemberPracticeSummaryReport = (year) => { 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) .then((results) => {