Skip to content

Commit

Permalink
feat: implementation review alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Jun 20, 2024
1 parent f4f1c2f commit c7a570c
Show file tree
Hide file tree
Showing 23 changed files with 134 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/config/mapping/allocations/cycles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"dataPath": "value",
"cycleFrom": "periodCovered",
"cycleTo": "",
"urlParams": "?$apply=filter(indicatorName eq 'Communicated Allocation - Reference Rate' AND financialDataSet eq 'CommunicatedAllocation_ReferenceRate')/groupby((periodCovered))&$orderby=periodCovered asc"
"urlParams": "?$apply=filter(indicatorName eq 'Communicated Allocation - Reference Rate' AND financialDataSet eq 'CommunicatedAllocation_ReferenceRate'<filterString>)/groupby((periodCovered))&$orderby=periodCovered asc"
}
2 changes: 1 addition & 1 deletion src/config/mapping/budgets/cycles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"dataPath": "value",
"cycleFrom": "implementationPeriod.periodFrom",
"cycleTo": "implementationPeriod.periodTo",
"urlParams": "?$apply=filter(contains(indicatorName, 'reference') AND financialDataSet eq 'GrantBudget_ReferenceRate')/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"
}
2 changes: 1 addition & 1 deletion src/config/mapping/disbursements/cycles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"dataPath": "value",
"cycleFrom": "implementationPeriod.periodFrom",
"cycleTo": "implementationPeriod.periodTo",
"urlParams": "?$apply=filter(contains(indicatorName, 'reference') AND financialDataSet eq 'Disbursement_ReferenceRate')/groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc"
"urlParams": "?$apply=filter(contains(indicatorName, 'reference') AND financialDataSet eq 'Disbursement_ReferenceRate'<filterString>)/groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc"
}
2 changes: 1 addition & 1 deletion src/config/mapping/expenditures/cycles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"dataPath": "value",
"cycleFrom": "implementationPeriod.periodFrom",
"cycleTo": "implementationPeriod.periodTo",
"urlParams": "?$apply=filter(indicatorName eq 'Expenditure: Module-Intervention - Reference Rate' AND isLatestReported eq true)/groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc"
"urlParams": "?$apply=filter(indicatorName eq 'Expenditure: Module-Intervention - Reference Rate' AND isLatestReported eq true<filterString>)/groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc"
}
4 changes: 2 additions & 2 deletions src/config/mapping/expenditures/heatmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"url2Items": ["HIV/AIDS", "Other"],
"fields": {
"principalRecipient": "implementationPeriod/grant/principalRecipient/name",
"principalRecipientSubType": "implementationPeriod/grant/principalRecipient/parent/name",
"principalRecipientType": "implementationPeriod/grant/principalRecipient/type/name",
"principalRecipientSubType": "implementationPeriod/grant/principalRecipient/type/name",
"principalRecipientType": "implementationPeriod/grant/principalRecipient/type/parent/name",
"component": "implementationPeriod/grant/<componentField>/name"
}
}
6 changes: 4 additions & 2 deletions src/config/mapping/filter-options/principal-recipients.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"dataPath": "value",
"label": "principalRecipient.name",
"value": "principalRecipient.name",
"type": "principalRecipient.type.name",
"typeCode": "principalRecipient.type.code"
"subType": "principalRecipient.type.name",
"subTypeCode": "principalRecipient.type.code",
"type": "principalRecipient.type.parent.name",
"typeCode": "principalRecipient.type.parent.code"
}
6 changes: 3 additions & 3 deletions src/config/mapping/fundingrequests/cycles.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dataPath": "value",
"cycleFrom": "implementationPeriod.periodFrom",
"cycleTo": "implementationPeriod.periodTo",
"urlParams": "?$apply=groupby((implementationPeriod/periodFrom,implementationPeriod/periodTo))&$orderby=implementationPeriod/periodFrom asc"
"cycleFrom": "periodFrom",
"cycleTo": "periodTo",
"urlParams": "?$apply=filter(<filterString>)/groupby((periodFrom,periodTo))&$orderby=periodFrom asc"
}
3 changes: 2 additions & 1 deletion src/config/mapping/grants/grant.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"lang": "narrativeLanguage"
},
"implementationPeriodArray": "implementationPeriods",
"implementationPeriodFrom": "implementationPeriodFrom",
"implementationPeriodFrom": "periodFrom",
"implementationPeriodTo": "periodTo",
"implementationPeriodTitle": "title",
"countryCode": "geography.code",
"countryName": "geography.name",
Expand Down
2 changes: 1 addition & 1 deletion src/config/mapping/pledgescontributions/bar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"donorBarIndicatorContribution": "Contribution - Reference Rate",
"donorBarIndicatorPledgeAmount": "plannedAmount",
"donorBarIndicatorContributionAmount": "actualAmount",
"donorBarUrlParams": "?$apply=filter(financialDataSet eq 'Pledges_Contributions'<filterString>)/groupby((donor/name,donor/type/name,donor/type/parent/name,indicatorName),aggregate(plannedAmount with sum as plannedAmount,actualAmount with sum as actualAmount))"
"donorBarUrlParams": "?$apply=filter(financialDataSet eq 'Pledges_Contributions' AND indicatorName in ('Pledge - Reference Rate','Contribution - Reference Rate')<filterString>)/groupby((donor/name,donor/type/name,donor/type/parent/name,indicatorName),aggregate(plannedAmount with sum as plannedAmount,actualAmount with sum as actualAmount))"
}
2 changes: 1 addition & 1 deletion src/config/mapping/pledgescontributions/cycles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"dataPath": "value",
"cycleFrom": "periodCovered",
"cycleTo": "",
"urlParams": "?$apply=filter(financialDataSet eq 'Pledges_Contributions')/groupby((periodCovered))&$orderby=periodCovered asc"
"urlParams": "?$apply=filter(financialDataSet eq 'Pledges_Contributions'<filterString>)/groupby((periodCovered))&$orderby=periodCovered asc"
}
2 changes: 1 addition & 1 deletion src/config/mapping/results/cycles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"dataPath": "value",
"cycleFrom": "resultValueYear",
"cycleTo": "",
"urlParams": "?$apply=filter(programmaticDataset eq 'Annual_Results')/groupby((resultValueYear))&$orderby=resultValueYear asc"
"urlParams": "?$apply=filter(programmaticDataset eq 'Annual_Results'<filterString>)/groupby((resultValueYear))&$orderby=resultValueYear asc"
}
2 changes: 1 addition & 1 deletion src/config/urls/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"FILTER_OPTIONS_COMPONENTS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/ActivityAreasGrouped?$filter=type eq 'Component'",
"FILTER_OPTIONS_REPLENISHMENT_PERIODS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/allFinancialIndicators?$apply=filter(financialDataSet eq 'Pledges_Contributions')/groupby((periodCovered))&$orderby=periodCovered asc",
"FILTER_OPTIONS_DONORS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/Donors?$apply=groupby((id,name,type/name))",
"FILTER_OPTIONS_PRINCIPAL_RECIPIENTS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/Grants?$apply=groupby((principalRecipient/type/name,principalRecipient/type/code,principalRecipient/name))",
"FILTER_OPTIONS_PRINCIPAL_RECIPIENTS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/Grants?$apply=groupby((principalRecipient/type/parent/name,principalRecipient/type/parent/code,principalRecipient/type/name,principalRecipient/type/code,principalRecipient/name))",
"FILTER_OPTIONS_RESULTS_COMPONENTS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/allProgrammaticIndicators?$apply=filter(programmaticDataset eq 'Annual_Results')/groupby((indicatorName,activityArea/name))",
"FILTER_OPTIONS_STATUS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/Statuses",
"FINANCIAL_INDICATORS": "https://api-gf-api-gf-02.azurewebsites.net/v4/odata/allFinancialIndicators",
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/allocations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,16 @@ export class AllocationsController {
@get('/allocations/cycles')
@response(200)
async cycles() {
const filterString = filterFinancialIndicators(
this.req.query,
AllocationCyclesFieldsMapping.urlParams,
'geography/code',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
.get(
`${urls.FINANCIAL_INDICATORS}${AllocationCyclesFieldsMapping.urlParams}`,
)
.get(url)
.then((resp: AxiosResponse) => {
const rawData = _.get(
resp.data,
Expand Down
12 changes: 10 additions & 2 deletions src/controllers/budgets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,16 @@ export class BudgetsController {
@get('/budgets/cycles')
@response(200)
async cycles() {
const filterString = filterFinancialIndicators(
this.req.query,
BudgetsCyclesMapping.urlParams,
'implementationPeriod/grant/geography/code',
'implementationPeriod/grant/activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

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

Expand Down Expand Up @@ -492,7 +500,7 @@ export class BudgetsController {
},
),
item => parseInt(item.value.toString().split(' - ')[0], 10),
'desc',
'asc',
);

return {data};
Expand Down
15 changes: 12 additions & 3 deletions src/controllers/disbursements.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,19 @@ export class DisbursementsController {
@get('/disbursements/cycles')
@response(200)
async cycles() {
const filterString = filterFinancialIndicators(
this.req.query,
DisbursementsCyclesMapping.urlParams,
[
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/geography/code',
],
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
.get(
`${urls.FINANCIAL_INDICATORS}${DisbursementsCyclesMapping.urlParams}`,
)
.get(url)
.then((resp: AxiosResponse) => {
const rawData = _.get(
resp.data,
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/expenditures.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,16 @@ export class ExpendituresController {
@get('/expenditures/cycles')
@response(200)
async cycles() {
const filterString = filterFinancialIndicators(
this.req.query,
ExpendituresCyclesMapping.urlParams,
'implementationPeriod/grant/geography/code',
'implementationPeriod/grant/activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
.get(`${urls.FINANCIAL_INDICATORS}${ExpendituresCyclesMapping.urlParams}`)
.get(url)
.then((resp: AxiosResponse) => {
const rawData = _.get(
resp.data,
Expand Down
49 changes: 39 additions & 10 deletions src/controllers/filteroptions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,21 +343,50 @@ export class FilteroptionsController {

const options: FilterGroupOption[] = [];

_.map(
_.groupBy(rawData, PrincipalRecipientMapping.type),
(prs, type) => {
const groupedByType = _.groupBy(
rawData,
PrincipalRecipientMapping.type,
);

_.forEach(groupedByType, (values, type) => {
if (type !== 'null') {
const typeOptions: FilterGroupOption = {
name: type,
value: _.get(prs[0], PrincipalRecipientMapping.typeCode, ''),
options: prs.map((pr: any) => ({
name: _.get(pr, PrincipalRecipientMapping.label, ''),
value: _.get(pr, PrincipalRecipientMapping.value, ''),
})),
value: _.get(values[0], PrincipalRecipientMapping.typeCode, ''),
options: [],
};

const groupedBySubType = _.groupBy(
values,
PrincipalRecipientMapping.subType,
);

_.forEach(groupedBySubType, (subValues, subType) => {
const subTypeOptions: FilterGroupOption = {
name: subType,
value: _.get(
subValues[0],
PrincipalRecipientMapping.subTypeCode,
'',
),
options: _.orderBy(
subValues.map((subValue: any) => ({
name: _.get(subValue, PrincipalRecipientMapping.label, ''),
value: _.get(subValue, PrincipalRecipientMapping.value, ''),
})),
'name',
'asc',
),
};

typeOptions.options?.push(subTypeOptions);
});

typeOptions.options = _.orderBy(typeOptions.options, 'name', 'asc');

options.push(typeOptions);
},
);
}
});

return {
data: {
Expand Down
12 changes: 10 additions & 2 deletions src/controllers/fundingrequests.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,24 @@ export class FundingRequestsController {
@param.path.string('countryCode') countryCode: string,
) {
return axios
.get(`http://localhost:4200/funding-requests?geographies=${countryCode}`)
.get(
`http://localhost:4200/funding-requests?geographies=${countryCode}&periods=${this.req.query.periods}`,
)
.then((resp: AxiosResponse) => resp.data)
.catch(handleDataApiError);
}

@get('/funding-requests/cycles')
@response(200)
async cycles() {
const filterString = filterFundingRequests(
this.req.query,
CyclesMapping.urlParams,
);
const url = `${urls.FUNDING_REQUESTS}/${filterString}`;

return axios
.get(`${urls.FINANCIAL_INDICATORS}${CyclesMapping.urlParams}`)
.get(url)
.then((resp: AxiosResponse) => {
const rawData = _.get(resp.data, CyclesMapping.dataPath, []);

Expand Down
6 changes: 5 additions & 1 deletion src/controllers/grants.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ export class GrantsController {
['asc'],
).map((p, index: number) => ({
code: index + 1,
name: `Implementation Period ${index + 1}`,
name: `Implementation Period ${_.get(
p,
GrantMapping.implementationPeriodFrom,
'',
)}-${_.get(p, GrantMapping.implementationPeriodTo, '')}`,
title: _.get(p, GrantMapping.implementationPeriodTitle, ''),
})),
countryName: _.get(raw, GrantMapping.countryName, ''),
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/pledgescontributions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,16 @@ export class PledgescontributionsController {
@get('/pledges-contributions/cycles')
@response(200)
async cycles() {
const filterString = filterFinancialIndicators(
this.req.query,
PledgesContributionsCyclesFieldsMapping.urlParams,
['donor/geography/name', 'donor/geography/code'],
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
.get(
`${urls.FINANCIAL_INDICATORS}${PledgesContributionsCyclesFieldsMapping.urlParams}`,
)
.get(url)
.then((resp: AxiosResponse) => {
const rawData = _.get(
resp.data,
Expand Down
10 changes: 7 additions & 3 deletions src/controllers/results.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,14 @@ export class ResultsController {
@get('/results/cycles')
@response(200)
async cycles() {
const filterString = filterProgrammaticIndicators(
this.req.query,
ResultsCyclesMappingFields.urlParams,
);
const url = `${urls.PROGRAMMATIC_INDICATORS}/${filterString}`;

return axios
.get(
`${urls.PROGRAMMATIC_INDICATORS}${ResultsCyclesMappingFields.urlParams}`,
)
.get(url)
.then((resp: AxiosResponse) => {
const rawData = _.get(
resp.data,
Expand Down
6 changes: 4 additions & 2 deletions src/utils/filtering/financialIndicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ const MAPPING = {
donor: 'donor/name',
donorType: 'donor/type/name',
principalRecipient: 'implementationPeriod/grant/principalRecipient/name',
principalRecipientType:
principalRecipientSubType:
'implementationPeriod/grant/principalRecipient/type/name',
principalRecipientType:
'implementationPeriod/grant/principalRecipient/type/parent/name',
period: 'periodCovered',
year: 'implementationPeriod/periodFrom',
yearTo: 'implementationPeriod/periodTo',
Expand Down Expand Up @@ -108,7 +110,7 @@ export function filterFinancialIndicators(
const periods = _.filter(
_.get(params, 'periods', '').split(','),
(o: string) => o.length > 0,
).map((period: string) => `'${period}'`);
).map((period: string) => `'${period.replace(/ /g, '')}'`);
if (periods.length > 0) {
str += `${str.length > 0 ? ' AND ' : ''}${MAPPING.period}${
filtering.in
Expand Down
2 changes: 1 addition & 1 deletion src/utils/filtering/fundingRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function filterFundingRequests(
const periods = _.filter(
_.get(params, 'periods', '').split(','),
(o: string) => o.length > 0,
).map((period: string) => period);
).map((period: string) => `'${period}'`);
if (periods.length > 0) {
str += `${str.length > 0 ? ' AND ' : ''}${MAPPING.period}${
filtering.in
Expand Down

0 comments on commit c7a570c

Please sign in to comment.