Skip to content

Commit

Permalink
feat: filtering adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Jun 13, 2024
1 parent a4ec920 commit 1d27806
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 36 deletions.
19 changes: 18 additions & 1 deletion src/controllers/allocations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export class AllocationsController {
let filterString = filterFinancialIndicators(
this.req.query,
AllocationCumulativeByCyclesFieldsMapping.urlParams,
'geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -187,6 +189,8 @@ export class AllocationsController {
const filterString = filterFinancialIndicators(
this.req.query,
AllocationSunburstFieldsMapping.urlParams,
'geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -229,7 +233,12 @@ export class AllocationsController {
urlParams = AllocationTreemapFieldsMapping.urlParams[1];
}
}
const filterString = filterFinancialIndicators(this.req.query, urlParams);
const filterString = filterFinancialIndicators(
this.req.query,
urlParams,
'geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
Expand Down Expand Up @@ -301,6 +310,8 @@ export class AllocationsController {
const filterString = filterFinancialIndicators(
this.req.query,
AllocationTableFieldsMapping.urlParams,
'geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -395,10 +406,14 @@ export class AllocationsController {
let filterString = filterFinancialIndicators(
this.req.query,
AllocationRadialFieldsMapping.urlParams,
'geography/name',
'activityArea/name',
);
let filterString2 = filterFinancialIndicators(
this.req.query,
AllocationRadialFieldsMapping.countriesCountUrlParams,
'geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand All @@ -423,6 +438,8 @@ export class AllocationsController {
let filterString = filterFinancialIndicators(
{...this.req.query, geographies: countryCode},
AllocationRadialFieldsMapping.urlParamsLocation,
'geography/name',
'activityArea/name',
);

const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;
Expand Down
61 changes: 44 additions & 17 deletions src/controllers/budgets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export class BudgetsController {
const filterString = filterFinancialIndicators(
this.req.query,
BudgetsRadialFieldsMapping.urlParams,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand All @@ -129,6 +131,8 @@ export class BudgetsController {
const filterString = filterFinancialIndicators(
this.req.query,
BudgetsSankeyFieldsMapping.urlParams,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -243,6 +247,8 @@ export class BudgetsController {
'<componentField>',
componentField,
),
'implementationPeriod/grant/geography/name',
`${componentField}/parent/parent/name`,
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -290,6 +296,8 @@ export class BudgetsController {
const filterString = filterFinancialIndicators(
this.req.query,
BudgetsTableFieldsMapping.urlParams,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -375,26 +383,31 @@ export class BudgetsController {
.then((resp: AxiosResponse) => {
const rawData = _.get(resp.data, BudgetsCyclesMapping.dataPath, []);

const data = _.map(
_.filter(
rawData,
item => _.get(item, BudgetsCyclesMapping.cycleFrom, null) !== null,
),
(item, index) => {
const from = _.get(item, BudgetsCyclesMapping.cycleFrom, '');
const to = _.get(item, BudgetsCyclesMapping.cycleTo, '');
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;
let value = from;

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

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

return {data};
Expand All @@ -419,6 +432,8 @@ export class BudgetsController {
/<componentField>/g,
componentField,
),
'implementationPeriod/grant/geography/name',
`${componentField}/parent/parent/name`,
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -461,10 +476,14 @@ export class BudgetsController {
const filterString1 = filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParams,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const filterString2 = filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParamsOrganisations,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const url1 = `${urls.FINANCIAL_INDICATORS}/${filterString1}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand Down Expand Up @@ -627,10 +646,14 @@ export class BudgetsController {
const filterString1 = filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParams,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const filterString2 = filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParamsOrganisations,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const url1 = `${urls.FINANCIAL_INDICATORS}/${filterString1}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand Down Expand Up @@ -761,10 +784,14 @@ export class BudgetsController {
const filterString1 = filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParams,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const filterString2 = filterFinancialIndicators(
this.req.query,
BudgetsMetricsFieldsMapping.urlParamsOrganisations,
'implementationPeriod/grant/geography/name',
'implementationPeriod/grant/activityArea/name',
);
const url1 = `${urls.FINANCIAL_INDICATORS}/${filterString1}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand Down
10 changes: 10 additions & 0 deletions src/controllers/disbursements.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ export class DisbursementsController {
const filterString = filterFinancialIndicators(
this.req.query,
FinancialInsightsStatsMapping.urlParams,
'implementationPeriod/grant/geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -244,6 +246,8 @@ export class DisbursementsController {
'<componentField>',
componentField,
),
'implementationPeriod/grant/geography/name',
`${componentField}/name`,
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -284,10 +288,14 @@ export class DisbursementsController {
'<componentField>',
componentField,
),
'implementationPeriod/grant/geography/name',
`${componentField}/name`,
);
const filterString2 = filterFinancialIndicators(
this.req.query,
LineChartFieldsMapping.activitiesCountUrlParams,
'implementationPeriod/grant/geography/name',
`${componentField}/name`,
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand Down Expand Up @@ -341,6 +349,8 @@ export class DisbursementsController {
const filterString = filterFinancialIndicators(
this.req.query,
TableFieldsMapping.urlParams.replace('<componentField>', componentField),
'implementationPeriod/grant/geography/name',
`${componentField}/name`,
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down
11 changes: 10 additions & 1 deletion src/controllers/expenditures.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export class ExpendituresController {
'<columnField>',
[columnField, subColumnField].join(',').replace(/(^,)|(,$)/g, ''),
);
filterString = filterFinancialIndicators(this.req.query, filterString);
filterString = filterFinancialIndicators(
this.req.query,
filterString,
'implementationPeriod/grant/geography/name',
`${componentField}/parent/parent/name`,
);

const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -205,6 +210,8 @@ export class ExpendituresController {
/<componentField>/g,
componentField,
),
'implementationPeriod/grant/geography/name',
`${componentField}/parent/parent/name`,
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -253,6 +260,8 @@ export class ExpendituresController {
/<componentField>/g,
componentField,
),
'implementationPeriod/grant/geography/name',
`${componentField}/parent/parent/name`,
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down
23 changes: 22 additions & 1 deletion src/controllers/pledgescontributions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@ export class PledgescontributionsController {
const filterString1 = filterFinancialIndicators(
this.req.query,
PledgesContributionsStatsFieldsMapping.totalValuesUrlParams,
'donor/geography/name',
'activityArea/name',
);
const filterString2 = filterFinancialIndicators(
this.req.query,
PledgesContributionsStatsFieldsMapping.donorTypesCountUrlParams,
'donor/geography/name',
'activityArea/name',
);
const url1 = `${urls.FINANCIAL_INDICATORS}/${filterString1}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand Down Expand Up @@ -177,6 +181,8 @@ export class PledgescontributionsController {
const filterString = filterFinancialIndicators(
this.req.query,
PledgesContributionsBarFieldsMapping.donorBarUrlParams,
'donor/geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -301,7 +307,12 @@ export class PledgescontributionsController {
type === 'pledge'
? PledgesContributionsSunburstFieldsMapping.pledgeUrlParams
: PledgesContributionsSunburstFieldsMapping.contributionUrlParams;
const filterString = filterFinancialIndicators(this.req.query, urlParams);
const filterString = filterFinancialIndicators(
this.req.query,
urlParams,
'donor/geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

return axios
Expand Down Expand Up @@ -409,6 +420,8 @@ export class PledgescontributionsController {
const filterString = filterFinancialIndicators(
this.req.query,
PledgesContributionsBarFieldsMapping.donorBarUrlParams,
'donor/geography/name',
'activityArea/name',
);
const url = `${urls.FINANCIAL_INDICATORS}/${filterString}`;

Expand Down Expand Up @@ -532,10 +545,14 @@ export class PledgescontributionsController {
let filterString1 = filterFinancialIndicators(
this.req.query,
PledgesContributionsBarFieldsMapping.pledgesUrlParams,
'donor/geography/name',
'activityArea/name',
);
let filterString2 = filterFinancialIndicators(
this.req.query,
PledgesContributionsBarFieldsMapping.contributionsUrlParams,
'donor/geography/name',
'activityArea/name',
);
const url1 = `${urls.FINANCIAL_INDICATORS}/${filterString1}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand All @@ -554,13 +571,17 @@ export class PledgescontributionsController {
geographies: countryCode,
},
PledgesContributionsBarFieldsMapping.pledgesUrlParams,
'donor/geography/name',
'activityArea/name',
);
let filterString2 = filterFinancialIndicators(
{
...this.req.query,
geographies: countryCode,
},
PledgesContributionsBarFieldsMapping.contributionsUrlParams,
'donor/geography/name',
'activityArea/name',
);
const url1 = `${urls.FINANCIAL_INDICATORS}/${filterString1}`;
const url2 = `${urls.FINANCIAL_INDICATORS}/${filterString2}`;
Expand Down
Loading

0 comments on commit 1d27806

Please sign in to comment.