Skip to content

Commit

Permalink
feat: adjust principal recipients in location page
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Nov 13, 2023
1 parent 780aab2 commit 49479ba
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/config/mapping/location/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"portfolioManagerEmail": "portfolioManagerEmailAddress",
"multiCountryId": "multiCountryId",
"geoId": "geographicAreaId",
"prevPrincipalRecipientStatusFilter": "Administratively Closed,In Closure,Terminated",
"currPrincipalRecipientStatusFilter": "Active",
"principalRecipientAggregation": "$apply=<filterString>groupby((PrincipalRecipientId,PrincipalRecipientName,PrincipalRecipientShortName))",
"principalRecipientName": "principalRecipientName",
"principalRecipientShortName": "principalRecipientShortName",
Expand Down
62 changes: 54 additions & 8 deletions src/controllers/location.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ export class LocationController {
locationMappingFields.locationFinancialAggregation,
);
const financialUrl = `${urls.grantsNoCount}/?${filterString}`;
const principalRecipientsFilterString = getFilterString(
this.req.query,
const prevPrincipalRecipientsFilterString = getFilterString(
{
...this.req.query,
status: locationMappingFields.prevPrincipalRecipientStatusFilter,
},
locationMappingFields.principalRecipientAggregation,
);
const currPrincipalRecipientsFilterString = getFilterString(
{
...this.req.query,
status: locationMappingFields.currPrincipalRecipientStatusFilter,
},
locationMappingFields.principalRecipientAggregation,
);
const principalRecipientsUrl = `${urls.grantsNoCount}/?${principalRecipientsFilterString}`;
const prevPrincipalRecipientsUrl = `${urls.grantsNoCount}/?${prevPrincipalRecipientsFilterString}`;
const currPrincipalRecipientsUrl = `${urls.grantsNoCount}/?${currPrincipalRecipientsFilterString}`;
const contactsUrl = `${
urls.countrycontactinfo
}/?${locationMappingFields.contactsFilterString.replace(
Expand All @@ -66,7 +77,8 @@ export class LocationController {
.all([
axios.get(multicountriesUrl),
axios.get(financialUrl),
axios.get(principalRecipientsUrl),
axios.get(prevPrincipalRecipientsUrl),
axios.get(currPrincipalRecipientsUrl),
axios.get(contactsUrl),
])
.then(
Expand Down Expand Up @@ -96,13 +108,18 @@ export class LocationController {
multiCountryId: '',
},
);
const principalRecipientsResp = _.get(
const prevPrincipalRecipientsResp = _.get(
responses[2].data,
locationMappingFields.multiCountriesDataPath,
[],
);
const contactsResp = _.get(
const currPrincipalRecipientsResp = _.get(
responses[3].data,
locationMappingFields.multiCountriesDataPath,
[],
);
const contactsResp = _.get(
responses[4].data,
locationMappingFields.contactsDataPath,
[],
);
Expand Down Expand Up @@ -238,8 +255,37 @@ export class LocationController {
'asc',
)
: [],
principalRecipients: _.filter(
principalRecipientsResp.map((pr: any) => {
prevPrincipalRecipients: _.filter(
prevPrincipalRecipientsResp.map((pr: any) => {
const fullName = _.get(
pr,
locationMappingFields.principalRecipientName,
'',
);
const shortName = _.get(
pr,
locationMappingFields.principalRecipientShortName,
'',
);
const id = _.get(
pr,
locationMappingFields.principalRecipientId,
'',
);

return {
code: id,
name: `${fullName}${shortName ? ` (${shortName})` : ''}`,
};
}),
(pr: any) =>
pr.code &&
!_.find(currPrincipalRecipientsResp, {
[locationMappingFields.principalRecipientId]: pr.code,
}),
),
currPrincipalRecipients: _.filter(
currPrincipalRecipientsResp.map((pr: any) => {
const fullName = _.get(
pr,
locationMappingFields.principalRecipientName,
Expand Down

0 comments on commit 49479ba

Please sign in to comment.