Make Practice Summary Report stub

This commit is contained in:
Senad Uka
2019-06-19 11:23:58 +02:00
parent 9a8d95dd19
commit 3ec13983c6
20 changed files with 629 additions and 88 deletions

View File

@@ -3,23 +3,41 @@
const moment = require('moment-timezone');
const db = require('../../models/index');
const { incidentType } = require('../../constants/constants');
const Op = require('sequelize').Op;
const { incidentType, UI_TIMEZONE, DEFAULT_DATE_FORMAT, integrationServiceErrors } = require('../../constants/constants');
const { fetchAllMembers } = require('../officeRnD/members');
const { fetchOffices, fetchResources } = require('../officeRnD/resources');
const getUnlockedIncidents = () => {
const getUnlockedIncidents = (startDate, endDate, memberId) => {
const attributes = ['id', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'incidentLevel', 'incidentLevelPrice'];
const filters = {};
if (startDate && endDate) {
filters.bookingStart = {
[Op.and]: {
[Op.gte]: startDate.utc().toISOString(),
[Op.lte]: endDate.utc().toISOString(),
}
}
}
if (memberId){
filters.memberId = memberId;
}
return db.unlockedIncident.findAll({
attributes,
where: filters,
sort: [
['bookingStart', 'ASC']
]
});
};
const getUnscheduledIncidents = () => {
const getUnscheduledIncidents = (startDate, endDate, memberId) => {
const attributes = [
'id',
'memberId',
@@ -33,8 +51,24 @@ const getUnscheduledIncidents = () => {
'totalChargeFee'
];
const filters = {};
if (startDate && endDate) {
filters.bookingStart = {
[Op.and]: {
[Op.gte]: startDate.utc().toISOString(),
[Op.lte]: endDate.utc().toISOString(),
}
}
}
if (memberId){
filters.memberId = memberId;
}
return db.unscheduledIncident.findAll({
attributes,
where: filters,
sort: [
['bookingStart', 'ASC']
]
@@ -42,13 +76,24 @@ const getUnscheduledIncidents = () => {
};
const formatTime = (timestamp) => {
const timezone = process.env.UI_TIMEZONE || 'America/Los_Angeles';
return moment.tz(timestamp, timezone).format('MM/DD/YYYY hh:mm a');
return moment.tz(timestamp, UI_TIMEZONE).format('MM/DD/YYYY hh:mm a');
};
const getAllDoorLockIncidents = () => {
const getAllDoorLockIncidents = (dateRange, memberId) => {
return new Promise ((resolve, reject) => {
const dataFetchJobs = [fetchAllMembers(), fetchOffices(), fetchResources(), getUnlockedIncidents(), getUnscheduledIncidents()];
let startDate, endDate;
if (dateRange.startDate && dateRange.endDate){
startDate = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE);
endDate = moment.tz(dateRange.endDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE);
if (!startDate.isValid() || !endDate.isValid() || endDate.isBefore(startDate)){
reject(integrationServiceErrors.INVALID_DATE_RANGE);
return;
}
}
const dataFetchJobs = [fetchAllMembers(), fetchOffices(), fetchResources(), getUnlockedIncidents(startDate, endDate, memberId), getUnscheduledIncidents(startDate, endDate, memberId)];
Promise.all(dataFetchJobs)
.then((data) => {