MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / getUfEstimatePopulationByCode

Function getUfEstimatePopulationByCode

services/ibge/gov.js:65–87  ·  view source on GitHub ↗
(uf)

Source from the content-addressed store, hash-verified

63
64// reference: https://servicodados.ibge.gov.br/api/docs/agregados?versao=3#api-Variaveis-agregadosAgregadoPeriodosPeriodosVariaveisVariavelGet
65export const getUfEstimatePopulationByCode = async (uf) => {
66 const ufCode = mapUfToUfCode(uf);
67 const ESTIMATED_POPULATION_AGGREGATE_ID = 6579;
68 const ESTIMATED_POPULATION_VARIABLE_ID = 9324;
69 const LATEST_PERIOD = -1;
70
71 let { data } = await axios
72 .get(`${URL_AGGREGATES}/${ESTIMATED_POPULATION_AGGREGATE_ID}/periodos/${LATEST_PERIOD}/variaveis?localidades=N3[${ufCode}]`);
73
74 data = data.find((item) => item.id == ESTIMATED_POPULATION_VARIABLE_ID);
75
76 if(!data){
77 throw new InternalError('Empty data');
78 }
79
80 const result = data.resultados[0].series[0].serie;
81 const key = Object.keys(result)[0]
82
83 return {
84 "populacao_estimada": parseInt(result[key]),
85 "periodo": key
86 }
87}

Callers 1

actionFunction · 0.90

Calls 1

mapUfToUfCodeFunction · 0.85

Tested by

no test coverage detected