251 lines
4.9 KiB
Markdown
251 lines
4.9 KiB
Markdown
# Migracao do Frontend: `/pedidos/condvenda-7/:numped7`
|
|
|
|
## O que mudou
|
|
|
|
Antes, a API retornava uma lista achatada de itens:
|
|
|
|
```ts
|
|
PedidoCondVenda7RowDto[]
|
|
```
|
|
|
|
Agora, a API retorna uma lista de grupos logisticos:
|
|
|
|
```ts
|
|
PedidoCondVenda7GroupDto[]
|
|
```
|
|
|
|
Cada grupo ja vem separado no backend pela chave:
|
|
|
|
```txt
|
|
numped|tipoentrega|dtentrega|codfilialretira
|
|
```
|
|
|
|
## Regra para o frontend
|
|
|
|
- Nao agrupar por conta propria.
|
|
- Nao usar `hash` como chave de separacao.
|
|
- Nao inferir `tipoentrega` pelo primeiro item de uma lista mista.
|
|
- Gerar 1 etiqueta por grupo retornado pela API.
|
|
|
|
## Novo formato de resposta
|
|
|
|
```ts
|
|
type PedidoCondVenda7RowDto = {
|
|
numped: number
|
|
cgc: string
|
|
razaosocial: string
|
|
dtemissao: string
|
|
codfilial: number
|
|
filialvenda: string
|
|
codfilialretira: number
|
|
filialretira: string
|
|
data: string
|
|
numcar: number
|
|
codcli: number
|
|
cliente: string
|
|
codusur: number
|
|
vendedor: string
|
|
vlfrete: number
|
|
valor: number
|
|
tipoentrega: string
|
|
dtentrega: string | null
|
|
codprod: number
|
|
descricao: string
|
|
qt: number
|
|
hash: string
|
|
}
|
|
|
|
type PedidoCondVenda7GroupDto = {
|
|
groupKey: string
|
|
numped: number
|
|
tipoentrega: string
|
|
dtentrega: string | null
|
|
codfilialretira: number
|
|
filialretira: string
|
|
cgc: string
|
|
razaosocial: string
|
|
dtemissao: string
|
|
codfilial: number
|
|
filialvenda: string
|
|
data: string
|
|
numcar: number
|
|
codcli: number
|
|
cliente: string
|
|
codusur: number
|
|
vendedor: string
|
|
vlfrete: number
|
|
valor: number
|
|
hash: string
|
|
items: PedidoCondVenda7RowDto[]
|
|
}
|
|
```
|
|
|
|
## Exemplo de resposta
|
|
|
|
```json
|
|
[
|
|
{
|
|
"groupKey": "157073710|RETIRA POSTERIOR|2026-03-11T00:00:00.000Z|4",
|
|
"numped": 157073710,
|
|
"tipoentrega": "RETIRA POSTERIOR",
|
|
"dtentrega": "2026-03-11T00:00:00.000Z",
|
|
"codfilialretira": 4,
|
|
"filialretira": "JURUNENSE BR",
|
|
"cgc": "13772792000407",
|
|
"razaosocial": "JURUNENSE HOME CENTER LTDA",
|
|
"dtemissao": "2026-03-17T18:58:51.000Z",
|
|
"codfilial": 4,
|
|
"filialvenda": "JURUNENSE BR",
|
|
"data": "2026-03-04T00:00:00.000Z",
|
|
"numcar": 0,
|
|
"codcli": 247485,
|
|
"cliente": "SORAIA CRISTINA SILVA DA COSTA",
|
|
"codusur": 157,
|
|
"vendedor": "BR - LOURIVAL EDVALDO COSTA FERREIRA",
|
|
"vlfrete": 0,
|
|
"valor": 827.83,
|
|
"hash": "4368D18F69C36357A1FD52271EF58861",
|
|
"items": [
|
|
{
|
|
"numped": 157073710,
|
|
"tipoentrega": "RETIRA POSTERIOR",
|
|
"codprod": 12586,
|
|
"descricao": "ARG COZ E BANHEIROS 20KG QUARTZ",
|
|
"qt": 7,
|
|
"hash": "4368D18F69C36357A1FD52271EF58861"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"groupKey": "157073714|ENTREGA|2026-03-11T00:00:00.000Z|12",
|
|
"numped": 157073714,
|
|
"tipoentrega": "ENTREGA",
|
|
"dtentrega": "2026-03-11T00:00:00.000Z",
|
|
"codfilialretira": 12,
|
|
"filialretira": "JURUNENSE DISTRITO",
|
|
"cgc": "13772792001217",
|
|
"razaosocial": "JURUNENSE HOME CENTER LTDA",
|
|
"dtemissao": "2026-03-17T18:58:51.000Z",
|
|
"codfilial": 12,
|
|
"filialvenda": "JURUNENSE DISTRITO",
|
|
"data": "2026-03-04T00:00:00.000Z",
|
|
"numcar": 8899569,
|
|
"codcli": 247485,
|
|
"cliente": "SORAIA CRISTINA SILVA DA COSTA",
|
|
"codusur": 157,
|
|
"vendedor": "BR - LOURIVAL EDVALDO COSTA FERREIRA",
|
|
"vlfrete": 0,
|
|
"valor": 0,
|
|
"hash": "4368D18F69C36357A1FD52271EF58861",
|
|
"items": [
|
|
{
|
|
"numped": 157073714,
|
|
"tipoentrega": "ENTREGA",
|
|
"codprod": 54001,
|
|
"descricao": "CER 66X66RT MILANO BG GR 2,18M",
|
|
"qt": 4,
|
|
"hash": "4368D18F69C36357A1FD52271EF58861"
|
|
},
|
|
{
|
|
"numped": 157073714,
|
|
"tipoentrega": "ENTREGA",
|
|
"codprod": 54067,
|
|
"descricao": "CER 45X45 BEGE 45 2,00M",
|
|
"qt": 14,
|
|
"hash": "4368D18F69C36357A1FD52271EF58861"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
```
|
|
|
|
## O que mudar no frontend
|
|
|
|
### 1. Tipagem
|
|
|
|
Trocar o tipo esperado da resposta:
|
|
|
|
```ts
|
|
const data: PedidoCondVenda7RowDto[] = await response.json()
|
|
```
|
|
|
|
por:
|
|
|
|
```ts
|
|
const groups: PedidoCondVenda7GroupDto[] = await response.json()
|
|
```
|
|
|
|
### 2. Renderizacao
|
|
|
|
Antes:
|
|
|
|
```ts
|
|
renderLabel(data)
|
|
```
|
|
|
|
Agora:
|
|
|
|
```ts
|
|
groups.forEach((group) => {
|
|
renderLabel(group)
|
|
})
|
|
```
|
|
|
|
### 3. Cabecalho da etiqueta
|
|
|
|
Os dados do cabecalho devem vir do grupo:
|
|
|
|
```ts
|
|
group.numped
|
|
group.tipoentrega
|
|
group.dtentrega
|
|
group.cliente
|
|
group.filialretira
|
|
group.vendedor
|
|
group.hash
|
|
group.valor
|
|
```
|
|
|
|
### 4. Itens da etiqueta
|
|
|
|
A tabela de produtos deve vir de:
|
|
|
|
```ts
|
|
group.items
|
|
```
|
|
|
|
Exemplo:
|
|
|
|
```ts
|
|
group.items.map((item) => ({
|
|
codprod: item.codprod,
|
|
descricao: item.descricao,
|
|
qt: item.qt,
|
|
}))
|
|
```
|
|
|
|
## Erro antigo que nao pode voltar
|
|
|
|
Se existir algo assim:
|
|
|
|
```ts
|
|
const firstItem = data[0]
|
|
const tipoEntrega = firstItem.tipoentrega
|
|
```
|
|
|
|
isso precisa sair se `data` representar mais de um pedido misturado.
|
|
|
|
Agora o correto e:
|
|
|
|
```ts
|
|
const tipoEntrega = group.tipoentrega
|
|
const items = group.items
|
|
```
|
|
|
|
## Resumo operacional
|
|
|
|
- 1 grupo retornado = 1 etiqueta
|
|
- cabecalho vem do grupo
|
|
- produtos vem de `group.items`
|
|
- separacao ja vem pronta do backend
|