Skip to content

Commit

Permalink
feat: financial metrics cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Jul 12, 2024
1 parent 943edd4 commit d870a9a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config/mapping/budgets/cycles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"dataPath": "value",
"cycleFrom": "implementationPeriod.periodFrom",
"cycleTo": "implementationPeriod.periodTo",
"urlParams": "?$apply=filter(contains(indicatorName, 'reference') AND financialDataSet eq 'GrantBudget_ReferenceRate'<filterString>)/groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc"
"urlParams": "?$apply=filter(contains(indicatorName, 'reference') AND financialDataSet eq 'GrantBudget_ReferenceRate'<filterString>)/groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc",
"urlParamsMetrics": "?$apply=filter(contains(indicatorName, 'reference') AND financialDataSet eq 'ImplementationPeriodFinancialMetricAmount'<filterString>)/groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc"
}
48 changes: 48 additions & 0 deletions src/controllers/budgets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,4 +1290,52 @@ export class BudgetsController {
)
.catch(handleDataApiError);
}

@get('/financial-metrics/cycles')
@response(200)
async metricsCycles() {
const filterString = filterFinancialIndicators(
this.req.query,
BudgetsCyclesMapping.urlParamsMetrics,
'implementationPeriod/grant/geography/code',
'implementationPeriod/grant/activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
.get(url)
.then((resp: AxiosResponse) => {
const rawData = _.get(resp.data, BudgetsCyclesMapping.dataPath, []);

const data = _.orderBy(
_.map(
_.filter(
rawData,
item =>
_.get(item, BudgetsCyclesMapping.cycleFrom, null) !== null,
),
(item, index) => {
const from = _.get(item, BudgetsCyclesMapping.cycleFrom, '');
const to = _.get(item, BudgetsCyclesMapping.cycleTo, '');

let value = from;

if (from && to) {
value = `${from} - ${to}`;
}

return {
name: `Cycle ${index + 1}`,
value,
};
},
),
item => parseInt(item.value.toString().split(' - ')[0], 10),
'asc',
);

return {data};
})
.catch(handleDataApiError);
}
}

0 comments on commit d870a9a

Please sign in to comment.