From bdb7bd68d29717e94af9135d70c8f1216260ab65 Mon Sep 17 00:00:00 2001 From: Stefanos Hadjipetrou Date: Fri, 24 Feb 2023 10:43:46 +0100 Subject: [PATCH] feat: add contacts to location overview page --- src/config/mapping/location/index.json | 9 +++ src/config/urls/index.json | 57 ++++++++--------- src/controllers/location.controller.ts | 84 +++++++++++++++----------- 3 files changed, 87 insertions(+), 63 deletions(-) diff --git a/src/config/mapping/location/index.json b/src/config/mapping/location/index.json index 445819d..b823bd0 100644 --- a/src/config/mapping/location/index.json +++ b/src/config/mapping/location/index.json @@ -7,6 +7,15 @@ "multiCountryCode": "multiCountryShortName", "countryName": "geographicArea.geographicAreaName", "countryCode": "geographicArea.geographicAreaCode_ISO3", + "contactsFilterString": "$filter=(geographicAreaCode_ISO3 eq '' OR multiCountryName eq '') AND organizationRoleName eq 'Coordinating Mechanism'", + "contactsDataPath": "value", + "contactOrganisationName": "organizationName", + "contactName": "contactFirstName", + "contactSurname": "contactLastName", + "contactRole": "contactRoleName", + "contactSalutation": "contactSalutation", + "contactPosition": "contactPositionTitle", + "contactEmail": "contactEmailAddress", "locationFinancialAggregation": "$apply=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'))", diff --git a/src/config/urls/index.json b/src/config/urls/index.json index f2b82a6..f9169d0 100644 --- a/src/config/urls/index.json +++ b/src/config/urls/index.json @@ -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" } diff --git a/src/controllers/location.controller.ts b/src/controllers/location.controller.ts index c8613c2..f92488f 100644 --- a/src/controllers/location.controller.ts +++ b/src/controllers/location.controller.ts @@ -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'; @@ -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 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( + //g, + location, + )}`; return axios .all([ axios.get(multicountriesUrl), axios.get(financialUrl), - axios.get(indicatorsUrl), axios.get(principalRecipientsUrl), + axios.get(contactsUrl), ]) .then( axios.spread((...responses) => { @@ -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: [ { @@ -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, @@ -233,6 +242,11 @@ export class LocationController { name: `${fullName}${shortName ? ` (${shortName})` : ''}`, }; }), + coordinatingMechanismContacts: _.orderBy( + contacts, + 'name', + 'asc', + ), }, ], };