Fix for loading
This commit is contained in:
53
services/integration/bookings.js
Normal file
53
services/integration/bookings.js
Normal file
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
const Op = require('sequelize').Op;
|
||||
const db = require('../../models/index');
|
||||
const moment = require('moment-timezone');
|
||||
|
||||
const { DEFAULT_DATE_FORMAT, UI_TIMEZONE } = require('../../constants/constants');
|
||||
|
||||
const getActiveBookingsForMembersInDateRange = (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',
|
||||
'reservationId',
|
||||
'memberId',
|
||||
'officeId',
|
||||
'resourceId',
|
||||
'start',
|
||||
'end',
|
||||
'timezone',
|
||||
'canceled',
|
||||
'hourlyRate'
|
||||
];
|
||||
|
||||
const filters = {
|
||||
canceled: false,
|
||||
};
|
||||
|
||||
if (startDate && endDate) {
|
||||
filters.start = {
|
||||
[Op.gte]: startDate.toISOString()
|
||||
};
|
||||
filters.end = {
|
||||
[Op.lte]: endDate.toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
if (memberIds.length > 0){
|
||||
filters.memberId = {
|
||||
[Op.in]: memberIds
|
||||
};
|
||||
}
|
||||
|
||||
return db.bookingReservation.findAll({
|
||||
attributes,
|
||||
where: filters,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getActiveBookingsForMembersInDateRange,
|
||||
};
|
||||
Reference in New Issue
Block a user