Add year selection for report; fetch report for selected year

This commit is contained in:
Bilal Catic
2019-08-09 00:05:17 +02:00
parent 7a3d49dee7
commit ecbacfd92d
5 changed files with 109 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
'use strict';
const moment = require('moment-timezone');
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase } = require('../services/officeRnD/resources');
const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports');
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
@@ -7,6 +9,8 @@ const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees'
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
const { checkIfProcessing } = require('../services/integration/processingStatus');
const { UI_TIMEZONE } = require('../constants/constants');
const getKnownOfficeResourceMappings = (req, res) => {
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources() ];
@@ -127,7 +131,22 @@ const checkProcessingStatus = (req, res) => {
};
const getPracticeSummaryReport = (req, res) => {
getMemberPracticeSummaryReport()
const year = req.params.year;
const currentYear = moment.tz(UI_TIMEZONE).year();
const parsedYear = parseInt(year);
if (!parsedYear || isNaN(parsedYear)){
res.status(400).send('Year is not a number');
return;
}
if (parsedYear > currentYear){
res.status(400).send('Selected year cannot be greater than current year');
return;
}
getMemberPracticeSummaryReport(parsedYear)
.then((result) => {
const pathToDownloadFile = `${__dirname}/../${result.reportPath}`;
res.download(pathToDownloadFile);