disable adding fees for current or month in future

This commit is contained in:
Bilal Catic
2019-09-06 07:43:51 +02:00
parent ddd375d4ce
commit 392c7f33c3

View File

@@ -10,7 +10,7 @@ const { reformatMembershipsName } = require('../services/officeRnD/memberships')
const { checkBookingChanges } = require('../services/integration/checkBookingChange'); const { checkBookingChanges } = require('../services/integration/checkBookingChange');
const { checkIfProcessing } = require('../services/integration/processingStatus'); const { checkIfProcessing } = require('../services/integration/processingStatus');
const { UI_TIMEZONE } = require('../constants/constants'); const { UI_TIMEZONE, DEFAULT_DATE_FORMAT } = require('../constants/constants');
const getKnownOfficeResourceMappings = (req, res) => { const getKnownOfficeResourceMappings = (req, res) => {
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources()]; const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources()];
@@ -117,48 +117,61 @@ const addFees = (req, res) => {
const dateRange = req.body && req.body.dateRange ? req.body.dateRange : {startDate: null, endDate: null}; const dateRange = req.body && req.body.dateRange ? req.body.dateRange : {startDate: null, endDate: null};
const { startDate, endDate } = dateRange; const { startDate, endDate } = dateRange;
if (startDate && endDate && Array.isArray(memberIds)){ const startDateMoment = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE);
checkBookingChanges()
.then(() => { if (startDate && endDate && startDateMoment.isValid() && Array.isArray(memberIds)){
deleteFeesFromORD(dateRange, memberIds) const currentMoment = moment.tz(UI_TIMEZONE);
.then((invoicedFees) => { const startMomentMonth = startDateMoment.month();
// TODO: Change this to parallel execution const startMomentYear = startDateMoment.year();
getMembersFeesForDateRange(dateRange, memberIds) const currentMonth = currentMoment.month();
.then(({allFees, memberships}) => { const currentYear = currentMoment.year();
addFeesToORD(allFees, invoicedFees)
.then((numberOfInsertedFees) => { if ((startMomentYear < currentYear) || (startMomentYear === currentYear && startMomentMonth < currentMonth)) {
reformatMembershipsName(memberships) checkBookingChanges()
.then(() => { .then(() => {
res.send({ deleteFeesFromORD(dateRange, memberIds)
status: 'ok', .then((invoicedFees) => {
numberOfInsertedFees // TODO: Change this to parallel execution
}); getMembersFeesForDateRange(dateRange, memberIds)
}) .then(({allFees, memberships}) => {
.catch((error) => { addFeesToORD(allFees, invoicedFees)
console.log('Error reformatting memberships name'); .then((numberOfInsertedFees) => {
console.log(error); reformatMembershipsName(memberships)
res.status(500).send(error); .then(() => {
}) res.send({
}) status: 'ok',
.catch((error) => { numberOfInsertedFees
console.log('Error adding fees'); });
res.status(500).send(error); })
}) .catch((error) => {
}) console.log('Error reformatting memberships name');
.catch((error) => { console.log(error);
console.log(error); res.status(500).send(error);
res.status(500).send(error); })
}) })
}) .catch((error) => {
.catch((error) => { console.log('Error adding fees');
console.log(error); res.status(500).send(error);
res.status(500).send(error); })
}); })
}) .catch((error) => {
.catch((error) => { console.log(error);
console.log('Error with updating booking reservations'); res.status(500).send(error);
res.status(500).send(error); })
}) })
.catch((error) => {
console.log(error);
res.status(500).send(error);
});
})
.catch((error) => {
console.log('Error with updating booking reservations');
res.status(500).send(error);
})
}else{
console.log('Selected month/year pair is current month or in the future');
res.status(400).send('Selected month/year pair is current month or in the future');
}
}else{ }else{
console.log('Date range is missing to send fees to ORD'); console.log('Date range is missing to send fees to ORD');
res.status(400).send('Date range is missing'); res.status(400).send('Date range is missing');