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

Function action

pages/api/ibge/uf/v1/[code].js:8–24  ·  view source on GitHub ↗
(request, response)

Source from the content-addressed store, hash-verified

6import NotFoundError from '@/errors/NotFoundError';
7
8const action = async (request, response) => {
9 const { code } = request.query;
10
11 const [ufRes, populationData] = await Promise.all([
12 getUfByCode(code),
13 getUfEstimatePopulationByCode(code),
14 ]);
15
16 const { data: ufData, status } = ufRes;
17
18 if (!ufData || (Array.isArray(ufData) && ufData.length === 0)) {
19 throw new NotFoundError({ message: 'UF não encontrada.' });
20 }
21
22 response.status(status);
23 return response.json({ ...ufData, ...populationData });
24};
25
26export default app().get(action);

Callers

nothing calls this directly

Calls 2

getUfByCodeFunction · 0.90

Tested by

no test coverage detected