Skip to content

Commit

Permalink
feat: datasets latest update date
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Oct 4, 2024
1 parent 25b79af commit 4417895
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
26 changes: 13 additions & 13 deletions src/config/mapping/latestupdate/index.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
{
"dataPath": "value[0]",
"updated": "dateTimeUpdated",
"created": "dateTimeCreated",
"dataPath": "value",
"updated": "lastUpdated",
"dataset": "dataset",
"datasets": [
{
"name": "allocations",
"url": "https://fetch.theglobalfund.org/v4/odata/allFinancialIndicators?$filter=indicatorName eq 'Communicated Allocation - Reference Rate' AND financialDataSet eq 'CommunicatedAllocation_ReferenceRate'&$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "CommunicatedAllocation_ReferenceRate"
},
{
"name": "budgets",
"url": "https://fetch.theglobalfund.org/v4/odata/allFinancialIndicators?$filter=contains(indicatorName, 'reference') AND financialDataSet eq 'GrantBudget_ReferenceRate'&$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "GrantBudget_ReferenceRate"
},
{
"name": "disbursements",
"url": "https://fetch.theglobalfund.org/v4/odata/allFinancialIndicators?$filter=contains(indicatorName, 'reference') AND financialDataSet eq 'Disbursement_ReferenceRate'&$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Disbursement_ReferenceRate"
},
{
"name": "eligibility",
"url": "https://fetch.theglobalfund.org/v4/odata/Eligibility?$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Eligibility"
},
{
"name": "expenditures",
"url": "https://fetch.theglobalfund.org/v4/odata/allFinancialIndicators?$filter=financialDataSet eq 'Expenditure_Intervention_ReferenceRate' AND isLatestReported eq true&$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Expenditure_InvestmentLandscape_ReferenceRate"
},
{
"name": "funding_requests",
"url": "https://fetch.theglobalfund.org/v4/odata/FundingRequests?$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Funding_Requests"
},
{
"name": "geographies",
"url": "https://fetch.theglobalfund.org/v4/odata/Geographies?$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Geography"
},
{
"name": "grants",
"url": "https://fetch.theglobalfund.org/v4/odata/Grants?$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Grants"
},
{
"name": "pledges-contributions",
"url": "https://fetch.theglobalfund.org/v4/odata/allFinancialIndicators?$filter=financialDataSet eq 'Pledges_Contributions' AND indicatorName eq 'Pledge - Reference Rate'&$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Pledges_Contributions"
},
{
"name": "results",
"url": "https://fetch.theglobalfund.org/v4/odata/allProgrammaticIndicators?$filter=programmaticDataset eq 'Annual_Results'&$top=1&$orderby=dateTimeUpdated desc,dateTimeCreated desc&$select=dateTimeUpdated,dateTimeCreated"
"datasetLabel": "Annual_Results"
}
]
}
3 changes: 2 additions & 1 deletion src/config/urls/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"GEOGRAPHIES": "https://fetch.theglobalfund.org/v4/odata/Geographies",
"FUNDING_REQUESTS": "https://fetch.theglobalfund.org/v4/odata/FundingRequests",
"DOCUMENTS": "https://fetch.theglobalfund.org/v4/odata/Documents",
"ELIGIBILITY": "https://fetch.theglobalfund.org/v4/odata/Eligibility"
"ELIGIBILITY": "https://fetch.theglobalfund.org/v4/odata/Eligibility",
"DATASET_INFORMATION": "https://fetch.theglobalfund.org/v4.1/odata/DatasetInformation?a=b"
}
26 changes: 10 additions & 16 deletions src/controllers/latestupdate.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,25 @@ import axios from 'axios';
import _ from 'lodash';
import moment from 'moment';
import LatestUpdateMapping from '../config/mapping/latestupdate/index.json';
import urls from '../config/urls/index.json';

export class LatestUpdateController {
constructor(@inject(RestBindings.Http.REQUEST) private req: Request) {}

@get('/latest-update')
@response(200)
async latestUpdate() {
const responses = await Promise.all(
LatestUpdateMapping.datasets.map(dataset => axios.get(dataset.url)),
);
const response = await axios.get(urls.DATASET_INFORMATION);
const rawData = _.get(response.data, LatestUpdateMapping.dataPath, []);

const data = responses.map((response, index) => {
const updated = _.get(
response,
`data.${LatestUpdateMapping.dataPath}[${LatestUpdateMapping.updated}]`,
'',
);
const created = _.get(
response,
`data.${LatestUpdateMapping.dataPath}[${LatestUpdateMapping.created}]`,
'',
);
const data = LatestUpdateMapping.datasets.map(dataset => {
const fDataset = _.find(rawData, {
[LatestUpdateMapping.dataset]: dataset.datasetLabel,
});
const updated = _.get(fDataset, `[${LatestUpdateMapping.updated}]`, '');
return {
name: _.get(LatestUpdateMapping.datasets, `[${index}].name`, ''),
date: moment(updated ?? created).format('DD MMMM YYYY'),
name: dataset.name,
date: moment(updated).format('DD MMMM YYYY'),
};
});

Expand Down

0 comments on commit 4417895

Please sign in to comment.