(request, response)
| 3 | import { getNcmData } from '@/services/sefaz'; |
| 4 | |
| 5 | async function getNcmByCode(request, response) { |
| 6 | const { code } = request.query; |
| 7 | const ncmCode = code.replace(/\D/g, ''); |
| 8 | const allNcmData = await getNcmData(); |
| 9 | const ncmData = allNcmData.find( |
| 10 | ({ codigo }) => codigo.replace(/\D/g, '') === ncmCode |
| 11 | ); |
| 12 | |
| 13 | if (!ncmData) { |
| 14 | throw new NotFoundError({ |
| 15 | message: 'Código NCM não encontrado', |
| 16 | type: 'NCM_CODE_NOT_FOUND', |
| 17 | }); |
| 18 | } |
| 19 | |
| 20 | return response.status(200).json(ncmData); |
| 21 | } |
| 22 | |
| 23 | export default app().get(getNcmByCode); |
nothing calls this directly
no test coverage detected