add cep and cnpj to api
This commit is contained in:
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user