(request, response)
| 6 | import NotFoundError from '@/errors/NotFoundError'; |
| 7 | |
| 8 | const 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 | |
| 26 | export default app().get(action); |
nothing calls this directly
no test coverage detected