Skip to content

Commit

Permalink
feat: expenditures opts
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Jul 11, 2024
1 parent 69f3d45 commit 294d20f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/config/mapping/expenditures/availability.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dataPath": "@odata.count",
"urlParams": "?$count=true&$top=0&$filter=financialDataSet eq 'Expenditure_Intervention_ReferenceRate' AND isAnnualized eq true<filterString>"
}
7 changes: 6 additions & 1 deletion src/config/mapping/expenditures/heatmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"principalRecipient": "implementationPeriod/grant/principalRecipient/name",
"principalRecipientSubType": "implementationPeriod/grant/principalRecipient/type/name",
"principalRecipientType": "implementationPeriod/grant/principalRecipient/type/parent/name",
"component": "implementationPeriod/grant/<componentField>/name"
"component": "implementationPeriod/grant/<componentField>/name",
"module": "<componentField>/parent/name",
"intervention": "<componentField>/name",
"investmentLandscape1": "financialCategory/parent/parent/name",
"investmentLandscape2": "financialCategory/parent/name",
"costCategory": "financialCategory/name"
}
}
57 changes: 57 additions & 0 deletions src/controllers/expenditures.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {inject} from '@loopback/core';
import {get, param, Request, response, RestBindings} from '@loopback/rest';
import axios, {AxiosResponse} from 'axios';
import _ from 'lodash';
import ExpendituresAvailabilityMapping from '../config/mapping/expenditures/availability.json';
import ExpendituresBarChartMapping from '../config/mapping/expenditures/bar.json';
import ExpendituresCyclesMapping from '../config/mapping/expenditures/cycles.json';
import ExpendituresHeatmapMapping from '../config/mapping/expenditures/heatmap.json';
Expand Down Expand Up @@ -81,6 +82,12 @@ export class ExpendituresController {
];
}
let filterString = ExpendituresHeatmapMapping.urlParams;
if (row.indexOf('investmentLandscape1') > -1) {
filterString = filterString.replace(
'Expenditure_Intervention_ReferenceRate',
'Expenditure_InvestmentLandscape_ReferenceRate',
);
}
let rowField = '';
let subRowField = '';
let subSubRowField = '';
Expand Down Expand Up @@ -129,6 +136,17 @@ export class ExpendituresController {
ExpendituresHeatmapMapping.fields.component,
).replace(/<componentField>/g, componentField);
}
rowField = rowField.replace(/<componentField>/g, componentField);
subRowField = subRowField.replace(/<componentField>/g, componentField);
subSubRowField = subSubRowField.replace(
/<componentField>/g,
componentField,
);
columnField = columnField.replace(/<componentField>/g, componentField);
subColumnField = subColumnField.replace(
/<componentField>/g,
componentField,
);
const rowFieldArray = [rowField, subRowField, subSubRowField].filter(
item => item.length > 0,
);
Expand Down Expand Up @@ -464,4 +482,43 @@ export class ExpendituresController {
})
.catch(handleDataApiError);
}

@get('/has/expenditures')
@response(200)
async hasExpenditures() {
let geographyMappings = [
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
];
if (this.req.query.geographyGrouping === 'Portfolio View') {
geographyMappings = [
'implementationPeriod/grant/geography_PortfolioView/name',
'implementationPeriod/grant/geography_PortfolioView/code',
];
} else if (this.req.query.geographyGrouping === 'Board Constituency View') {
geographyMappings = [
'implementationPeriod/grant/geography_BoardConstituencyView/name',
'implementationPeriod/grant/geography_BoardConstituencyView/code',
];
}
const filterString = filterFinancialIndicators(
this.req.query,
ExpendituresAvailabilityMapping.urlParams,
geographyMappings,
'implementationPeriod/grant/activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
.get(url)
.then((resp: AxiosResponse) => {
return {
data: {
hasExpenditures:
_.get(resp.data, ExpendituresAvailabilityMapping.dataPath, 0) > 0,
},
};
})
.catch(handleDataApiError);
}
}

0 comments on commit 294d20f

Please sign in to comment.