add cep and cnpj to api

This commit is contained in:
2025-12-28 18:48:55 -03:00
parent 8b81d5c245
commit f7d1854309
7 changed files with 185 additions and 151 deletions

View File

@@ -0,0 +1,30 @@
import type { Route } from './+types/route'
import { data } from 'react-router'
import lodash from 'lodash'
export async function loader({ params }: Route.LoaderArgs) {
const r = await fetch(`https://minhareceita.org/${params.cnpj}`, {
method: 'GET'
})
if (!r.ok) {
throw new Response(await r.text(), { status: r.status })
}
const json = (await r.json()) as any
const addr = lodash.startCase(
lodash.toLower(`${json.descricao_tipo_de_logradouro} ${json.logradouro}`)
)
return data({
name: json.razao_social,
address: {
postcode: json.cep,
address1: `${addr}, ${json.numero}`,
neighborhood: lodash.capitalize(json.bairro),
city: lodash.capitalize(json.municipio),
state: json.uf
}
})
}