(uf)
| 63 | |
| 64 | // reference: https://servicodados.ibge.gov.br/api/docs/agregados?versao=3#api-Variaveis-agregadosAgregadoPeriodosPeriodosVariaveisVariavelGet |
| 65 | export 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 | } |
no test coverage detected