Skip to content

Commit

Permalink
feat: add contacts to location overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Feb 24, 2023
1 parent 427edb6 commit bdb7bd6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 63 deletions.
9 changes: 9 additions & 0 deletions src/config/mapping/location/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"multiCountryCode": "multiCountryShortName",
"countryName": "geographicArea.geographicAreaName",
"countryCode": "geographicArea.geographicAreaCode_ISO3",
"contactsFilterString": "$filter=(geographicAreaCode_ISO3 eq '<code>' OR multiCountryName eq '<code>') AND organizationRoleName eq 'Coordinating Mechanism'",
"contactsDataPath": "value",
"contactOrganisationName": "organizationName",
"contactName": "contactFirstName",
"contactSurname": "contactLastName",
"contactRole": "contactRoleName",
"contactSalutation": "contactSalutation",
"contactPosition": "contactPositionTitle",
"contactEmail": "contactEmailAddress",
"locationFinancialAggregation": "$apply=<filterString>groupby((GeographicAreaName,GeographicAreaId,MultiCountryName,MultiCountryId,PortfolioManager,PortfolioManagerEmailAddress),aggregate(TotalDisbursedAmount with sum as disbursed, TotalSignedAmount with sum as signed, TotalCommittedAmount with sum as committed))",
"locationFinancialDataPath": "value[0]",
"locationIndicatorsDefaultFilter": "(contains(indicator, 'GNI') OR contains(indicator, 'Life expectancy'))",
Expand Down
57 changes: 29 additions & 28 deletions src/config/urls/index.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"grants": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreements/?$count=true&",
"grantsNoCount": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreements",
"results": "https://fetch.theglobalfund.org/v3.3/odata/VReportingResults",
"documents": "https://fetch.theglobalfund.org/v3.3/odata/VProgramDocuments",
"disbursements": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreementDisbursements",
"commitments": "https://fetch.theglobalfund.org/v3.3/odata/GrantAgreementCommitments",
"vcommitments": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreementCommitments",
"grantDetailGrants": "https://fetch.theglobalfund.org/v3.3/odata/GrantAgreementImplementationPeriods",
"grantPeriods": "https://fetch.theglobalfund.org/v3.3/odata/GrantAgreementImplementationPeriods",
"vgrantPeriods": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreementImplementationPeriods",
"grantDetailDisbursements": "https://fetch.theglobalfund.org/v3.3/odata/GrantAgreementDisbursements",
"budgets": "https://fetch.theglobalfund.org/v3.3/odata/GrantAgreementImplementationPeriodDetailedBudgets",
"allocations": "https://fetch.theglobalfund.org/v3.3/odata/Allocations",
"eligibility": "https://fetch.theglobalfund.org/v3.3/odata/VEligibility",
"grants": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreements/?$count=true&",
"grantsNoCount": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreements",
"results": "https://fetch.theglobalfund.org/v3.4/odata/VReportingResults",
"documents": "https://fetch.theglobalfund.org/v3.4/odata/VProgramDocuments",
"disbursements": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreementDisbursements",
"commitments": "https://fetch.theglobalfund.org/v3.4/odata/GrantAgreementCommitments",
"vcommitments": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreementCommitments",
"grantDetailGrants": "https://fetch.theglobalfund.org/v3.4/odata/GrantAgreementImplementationPeriods",
"grantPeriods": "https://fetch.theglobalfund.org/v3.4/odata/GrantAgreementImplementationPeriods",
"vgrantPeriods": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreementImplementationPeriods",
"grantDetailDisbursements": "https://fetch.theglobalfund.org/v3.4/odata/GrantAgreementDisbursements",
"budgets": "https://fetch.theglobalfund.org/v3.4/odata/GrantAgreementImplementationPeriodDetailedBudgets",
"allocations": "https://fetch.theglobalfund.org/v3.4/odata/Allocations",
"eligibility": "https://fetch.theglobalfund.org/v3.4/odata/VEligibility",
"geojson": "https://data.theglobalfund.org/static/simple.geo.json",
"pledgescontributions": "https://fetch.theglobalfund.org/v3.3/odata/PledgesAndContributions",
"performancerating": "https://fetch.theglobalfund.org/v3.3/odata/GrantAgreementProgressUpdates",
"performanceframework": "https://fetch.theglobalfund.org/v3.3/odata/GrantAgreementImplementationPeriodPerformanceFrameworks",
"multicountries": "https://fetch.theglobalfund.org/v3.3/odata/MultiCountries",
"indicators": "https://fetch.theglobalfund.org/v3.3/odata/VNationalHealthAndDevelopmentIndicators",
"filteroptionslocations": "https://fetch.theglobalfund.org/v3.3/odata/GeographicAreas?$select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId&$expand=members($select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId;$expand=members($select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId;$expand=members($select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId;$expand=members)))&$filter=geographicAreaName eq 'World'",
"filteroptionsmulticountries": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreements?$apply=filter(multiCountryName%20ne%20null)/groupby((MultiCountryName,GeographicAreaCode_ISO3),aggregate(GrantAgreementId%20with%20countdistinct%20as%20count))&$orderby=count%20desc",
"filteroptionscomponents": "https://fetch.theglobalfund.org/v3.3/odata/Components",
"filteroptionspartnertypes": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreements?$apply=groupby((principalRecipientClassificationName,principalRecipientClassificationId,principalRecipientSubClassificationName,principalRecipientSubClassificationId,principalRecipientName,principalRecipientId))",
"filteroptionsstatus": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreements?$apply=groupby((grantAgreementStatusTypeName))",
"filteroptionsstatus1": "https://fetch.theglobalfund.org/v3.3/odata/VGrantAgreementImplementationPeriods?$apply=groupby((implementationPeriodStatusTypeName))",
"filteroptionsdonors": "https://fetch.theglobalfund.org/v3.3/odata/donors/?$filter=donorId%20eq%20c06eaea9-c81b-442b-b403-dc348f3734eb%20or%20donorId%20eq%2025188dfc-7567-4e08-b8d0-088a6b83f238%20or%20donorId%20eq%20641c05fa-129d-4b57-a213-b5f6852ddc5f%20or%20donorid%20eq%20cc30fc59-b2fa-49e3-aa5a-762727daa68c&$expand=members($expand=members($expand=members($expand=members)))",
"filteroptionsreplenishmentperiods": "https://fetch.theglobalfund.org/v3.3/odata/replenishmentperiods",
"multicountriescountriesdata": "https://fetch.theglobalfund.org/v3.3/odata/MultiCountries?$expand=MultiCountryComposition($select=GeographicArea;$expand=GeographicArea($select=GeographicAreaCode_ISO3))&$select=MultiCountryName,MultiCountryComposition"
"countrycontactinfo": "https://fetch.theglobalfund.org/v3.4/odata/VContacts",
"pledgescontributions": "https://fetch.theglobalfund.org/v3.4/odata/PledgesAndContributions",
"performancerating": "https://fetch.theglobalfund.org/v3.4/odata/GrantAgreementProgressUpdates",
"performanceframework": "https://fetch.theglobalfund.org/v3.4/odata/GrantAgreementImplementationPeriodPerformanceFrameworks",
"multicountries": "https://fetch.theglobalfund.org/v3.4/odata/MultiCountries",
"indicators": "https://fetch.theglobalfund.org/v3.4/odata/VNationalHealthAndDevelopmentIndicators",
"filteroptionslocations": "https://fetch.theglobalfund.org/v3.4/odata/GeographicAreas?$select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId&$expand=members($select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId;$expand=members($select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId;$expand=members($select=geographicAreaCode_ISO3,geographicAreaCode_ISO2,geographicAreaId,geographicAreaName,geographicAreaParentId;$expand=members)))&$filter=geographicAreaName eq 'World'",
"filteroptionsmulticountries": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreements?$apply=filter(multiCountryName%20ne%20null)/groupby((MultiCountryName,GeographicAreaCode_ISO3),aggregate(GrantAgreementId%20with%20countdistinct%20as%20count))&$orderby=count%20desc",
"filteroptionscomponents": "https://fetch.theglobalfund.org/v3.4/odata/Components",
"filteroptionspartnertypes": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreements?$apply=groupby((principalRecipientClassificationName,principalRecipientClassificationId,principalRecipientSubClassificationName,principalRecipientSubClassificationId,principalRecipientName,principalRecipientId))",
"filteroptionsstatus": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreements?$apply=groupby((grantAgreementStatusTypeName))",
"filteroptionsstatus1": "https://fetch.theglobalfund.org/v3.4/odata/VGrantAgreementImplementationPeriods?$apply=groupby((implementationPeriodStatusTypeName))",
"filteroptionsdonors": "https://fetch.theglobalfund.org/v3.4/odata/donors/?$filter=donorId%20eq%20c06eaea9-c81b-442b-b403-dc348f3734eb%20or%20donorId%20eq%2025188dfc-7567-4e08-b8d0-088a6b83f238%20or%20donorId%20eq%20641c05fa-129d-4b57-a213-b5f6852ddc5f%20or%20donorid%20eq%20cc30fc59-b2fa-49e3-aa5a-762727daa68c&$expand=members($expand=members($expand=members($expand=members)))",
"filteroptionsreplenishmentperiods": "https://fetch.theglobalfund.org/v3.4/odata/replenishmentperiods",
"multicountriescountriesdata": "https://fetch.theglobalfund.org/v3.4/odata/MultiCountries?$expand=MultiCountryComposition($select=GeographicArea;$expand=GeographicArea($select=GeographicAreaCode_ISO3))&$select=MultiCountryName,MultiCountryComposition"
}
84 changes: 49 additions & 35 deletions src/controllers/location.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@loopback/rest';
import axios from 'axios';
import _ from 'lodash';
import filtering from '../config/filtering/index.json';
import locationMappingFields from '../config/mapping/location/index.json';
import urls from '../config/urls/index.json';
import {handleDataApiError} from '../utils/dataApiError';
Expand Down Expand Up @@ -51,30 +50,24 @@ export class LocationController {
locationMappingFields.locationFinancialAggregation,
);
const financialUrl = `${urls.grantsNoCount}/?${filterString}`;
const indicatorsUrl = `${urls.indicators}/?${filtering.filter_operator}${
filtering.param_assign_operator
}${locationMappingFields.locationIndicatorsDefaultFilter} ${
filtering.and_operator
} ${locationMappingFields.locationIndicatorsLocationFilter.replace(
'<location>',
location as string,
)}&${filtering.orderby}${filtering.param_assign_operator}${
locationMappingFields.locationIndicatorsDefaultOrder
}&${filtering.page_size}${filtering.param_assign_operator}${
locationMappingFields.locationIndicatorsDefaultCap
}`;
const principalRecipientsFilterString = getFilterString(
this.req.query,
locationMappingFields.principalRecipientAggregation,
);
const principalRecipientsUrl = `${urls.grantsNoCount}/?${principalRecipientsFilterString}`;
const contactsUrl = `${
urls.countrycontactinfo
}/?${locationMappingFields.contactsFilterString.replace(
/<code>/g,
location,
)}`;

return axios
.all([
axios.get(multicountriesUrl),
axios.get(financialUrl),
axios.get(indicatorsUrl),
axios.get(principalRecipientsUrl),
axios.get(contactsUrl),
])
.then(
axios.spread((...responses) => {
Expand Down Expand Up @@ -103,17 +96,50 @@ export class LocationController {
multiCountryId: '',
},
);
const locationIndicatorsResp = _.get(
const principalRecipientsResp = _.get(
responses[2].data,
locationMappingFields.locationIndicatorsDataPath,
locationMappingFields.multiCountriesDataPath,
[],
);
const principalRecipientsResp = _.get(
const contactsResp = _.get(
responses[3].data,
locationMappingFields.multiCountriesDataPath,
locationMappingFields.contactsDataPath,
[],
);

const formattedContactsResp = contactsResp.map((c: any) => ({
orgName: _.get(
c,
locationMappingFields.contactOrganisationName,
'',
),
name: _.get(c, locationMappingFields.contactName, ''),
surname: _.get(c, locationMappingFields.contactSurname, ''),
role: _.get(c, locationMappingFields.contactRole, ''),
salutation: _.get(c, locationMappingFields.contactSalutation, ''),
position: _.get(c, locationMappingFields.contactPosition, ''),
email: _.get(c, locationMappingFields.contactEmail, ''),
}));

const contacts: any[] = [];
const groupedBy = _.groupBy(formattedContactsResp, 'orgName');

Object.keys(groupedBy).forEach((key: string) => {
contacts.push({
name: key,
items: _.orderBy(groupedBy[key], 'role', 'asc').map(
(item: any) => ({
name: `${item.salutation} ${
item.name
} ${item.surname.toUpperCase()}`,
role: item.role,
position: item.position,
email: item.email,
}),
),
});
});

return {
data: [
{
Expand Down Expand Up @@ -194,23 +220,6 @@ export class LocationController {
'asc',
)
: [],
indicators: locationIndicatorsResp.map((indicator: any) => ({
name: _.get(
indicator,
locationMappingFields.locationIndicatorName,
'',
),
year: _.get(
indicator,
locationMappingFields.locationIndicatorYear,
'',
),
value: _.get(
indicator,
locationMappingFields.locationIndicatorValue,
'',
),
})),
principalRecipients: principalRecipientsResp.map((pr: any) => {
const fullName = _.get(
pr,
Expand All @@ -233,6 +242,11 @@ export class LocationController {
name: `${fullName}${shortName ? ` (${shortName})` : ''}`,
};
}),
coordinatingMechanismContacts: _.orderBy(
contacts,
'name',
'asc',
),
},
],
};
Expand Down

0 comments on commit bdb7bd6

Please sign in to comment.