Ignoring prefixed fee names

This commit is contained in:
Senad Uka
2019-09-05 14:52:10 +02:00
parent 12e94c30e8
commit cf0f96eb83
3 changed files with 20 additions and 5 deletions

View File

@@ -123,6 +123,10 @@ const discounts = {
}; };
const DISCOUNT_PLANS = process.env.DISCOUNT_PLANS.split(',').map(planName => planName.trim()) || []; const DISCOUNT_PLANS = process.env.DISCOUNT_PLANS.split(',').map(planName => planName.trim()) || [];
const CUSTOM_FEES_PREFIXES = process.env.CUSTOM_FEES_PREFIXES.split(',')
.map(prefix => prefix.trim())
.filter(prefix => prefix && prefix.length ? prefix.length > 0 : false) || [];
const UNPAID_FEE_STATUS = 'not_paid'; const UNPAID_FEE_STATUS = 'not_paid';
module.exports = { module.exports = {
@@ -148,4 +152,5 @@ module.exports = {
discounts, discounts,
DISCOUNT_PLANS, DISCOUNT_PLANS,
UNPAID_FEE_STATUS, UNPAID_FEE_STATUS,
CUSTOM_FEES_PREFIXES,
}; };

View File

@@ -37,6 +37,8 @@ ORD_OAUTH_CLIENT_ID=Client ID for this app, created in ORD; Used to obtain OAUTH
ORD_OAUTH_CLIENT_SECRET=Client secret for this app; Used to obtain OAUTH token ORD_OAUTH_CLIENT_SECRET=Client secret for this app; Used to obtain OAUTH token
ORD_OAUTH_URL=https://identity.officernd.com/oauth/token ORD_OAUTH_URL=https://identity.officernd.com/oauth/token
CUSTOM_FEES_PREFIXES=Array of prefixes to recognize manually added fees. Comma-separated
#More about pool option : http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html #More about pool option : http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html
DB_POOL_MAX_CONNECTIONS=Maximum number of connection in pool (ex. 18) DB_POOL_MAX_CONNECTIONS=Maximum number of connection in pool (ex. 18)
DB_POOL_ACQUIRE=The maximum time, in milliseconds, that pool will try to get connection before throwing error (ex. 120000) DB_POOL_ACQUIRE=The maximum time, in milliseconds, that pool will try to get connection before throwing error (ex. 120000)

View File

@@ -3,7 +3,7 @@
const moment = require('moment-timezone'); const moment = require('moment-timezone');
const { API } = require('../../helpers/api'); const { API } = require('../../helpers/api');
const { officeRnDAPIErrors, DEFAULT_DATE_FORMAT, UNPAID_FEE_STATUS } = require('../../constants/constants'); const { officeRnDAPIErrors, DEFAULT_DATE_FORMAT, UNPAID_FEE_STATUS, CUSTOM_FEES_PREFIXES } = require('../../constants/constants');
const deleteFeesFromORD = (dateRange, memberIds) => { const deleteFeesFromORD = (dateRange, memberIds) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -12,7 +12,7 @@ const deleteFeesFromORD = (dateRange, memberIds) => {
const asyncDataFetch = [API.get('fees'), API.get('plans')]; const asyncDataFetch = [API.get('fees'), API.get('plans')];
const invoicedFees = []; const feesToSkip = [];
Promise.all(asyncDataFetch) Promise.all(asyncDataFetch)
.then((responses) => { .then((responses) => {
@@ -45,19 +45,27 @@ const deleteFeesFromORD = (dateRange, memberIds) => {
const feeId = fee['_id']; const feeId = fee['_id'];
const isDateInDateRange = startDate.isSameOrBefore(date) && endDate.isSameOrAfter(date); const isDateInDateRange = startDate.isSameOrBefore(date) && endDate.isSameOrAfter(date);
const manuallyAddedFee = manualFeeNames.indexOf(name) !== -1; let manuallyAddedFee = false;
if (manualFeeNames.indexOf(name) === -1){
if (name && name[0] && CUSTOM_FEES_PREFIXES.indexOf(name[0]) !== -1){
manuallyAddedFee = true;
}
}else{
manuallyAddedFee = true;
}
const memberFeesShouldBeDeleted = filterByMemberIds ? memberIdsMap[member] : true; const memberFeesShouldBeDeleted = filterByMemberIds ? memberIdsMap[member] : true;
if (memberFeesShouldBeDeleted && isDateInDateRange && (status === UNPAID_FEE_STATUS) && !manuallyAddedFee) { if (memberFeesShouldBeDeleted && isDateInDateRange && (status === UNPAID_FEE_STATUS) && !manuallyAddedFee) {
feeIdsToRemove.push(feeId); feeIdsToRemove.push(feeId);
}else{ }else{
invoicedFees.push(fee); feesToSkip.push(fee);
} }
}); });
API.delete('fees', { data: feeIdsToRemove }) API.delete('fees', { data: feeIdsToRemove })
.then(() => { .then(() => {
resolve(invoicedFees); resolve(feesToSkip);
}) })
.catch((error) => { .catch((error) => {
console.log('error : ', error); console.log('error : ', error);