feat(resellers): expande cadastro (dados PJ, endereço, contatos, sócios) + busca de CNPJ
Mesma expansão feita no Cadastro de Cliente, aplicada a Revenda: razão social/nome fantasia, inscrição estadual, natureza jurídica, endereço, contatos e sócios — tabela reseller_partners nova. Endpoint POST /v1/resellers/:id/cnpj-lookup reaproveita o adapter lookupCnpj já existente (@eden/integrations), sem duplicar a lógica de consulta. Decisão deliberada: revenda não ganhou person_type (sempre tratada como PJ) e document continua livremente editável via PATCH genérico (diferente de client_registrations, que bloqueia pj_cnpj de propósito) — a busca de CNPJ aqui é só conveniência adicional, não uma trava nova. Suíte: 106/106 (100→106). pnpm turbo run typecheck build: 28/28. Testado ao vivo com CNPJ real (Petrobras, 10 sócios). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Expands the minimalist operational `resellers` cadastro (eden.md §1.7)
|
||||
* with the same PJ profile fields, address block, three contact roles, and
|
||||
* sócios/QSA table already shipped for `client_registrations` in this
|
||||
* session — enabling the same CNPJ-lookup autofill
|
||||
* (`packages/integrations/src/cnpj-lookup/lookup.ts`, `lookupCnpj`) for
|
||||
* Revenda. Mirrors `client_registrations`' `pj_*`/`address_*`/`contact_*`
|
||||
* shape, but WITHOUT the `pj_` prefix — there's no PF/PJ ambiguity on this
|
||||
* table (a reseller is always a company; `resellers.name` already plays
|
||||
* the role `pj_company_name` plays there, so only `trade_name` is new for
|
||||
* the "nome" side). No `person_type` column is added — deliberate, see
|
||||
* task notes; a reseller cadastro doesn't bifurcate PF/PJ.
|
||||
*
|
||||
* Deliberate divergence from `client_registrations`: `document` here stays
|
||||
* freely editable via the existing generic `PATCH /v1/resellers/:id` —
|
||||
* unlike `pj_cnpj`/`pf_cpf` there, which are locked out of the generic
|
||||
* admin PATCH. The CNPJ-lookup endpoint added alongside this migration
|
||||
* (`POST /v1/resellers/:id/cnpj-lookup`) is purely an additional
|
||||
* convenience action, not a replacement for manual editing.
|
||||
*/
|
||||
|
||||
exports.shorthands = undefined;
|
||||
|
||||
exports.up = (pgm) => {
|
||||
pgm.sql(`
|
||||
ALTER TABLE resellers
|
||||
ADD COLUMN trade_name TEXT,
|
||||
ADD COLUMN state_registration TEXT,
|
||||
ADD COLUMN municipal_registration TEXT,
|
||||
ADD COLUMN opening_date DATE,
|
||||
ADD COLUMN legal_nature TEXT,
|
||||
ADD COLUMN cnpj_situation TEXT,
|
||||
ADD COLUMN main_activity TEXT,
|
||||
ADD COLUMN address_zip TEXT,
|
||||
ADD COLUMN address_street TEXT,
|
||||
ADD COLUMN address_number TEXT,
|
||||
ADD COLUMN address_complement TEXT,
|
||||
ADD COLUMN address_neighborhood TEXT,
|
||||
ADD COLUMN address_city TEXT,
|
||||
ADD COLUMN address_state TEXT,
|
||||
ADD COLUMN address_country TEXT NOT NULL DEFAULT 'Brasil',
|
||||
ADD COLUMN contact_principal_name TEXT,
|
||||
ADD COLUMN contact_principal_email TEXT,
|
||||
ADD COLUMN contact_principal_phone TEXT,
|
||||
ADD COLUMN contact_financial_name TEXT,
|
||||
ADD COLUMN contact_financial_email TEXT,
|
||||
ADD COLUMN contact_financial_phone TEXT,
|
||||
ADD COLUMN contact_technical_name TEXT,
|
||||
ADD COLUMN contact_technical_email TEXT,
|
||||
ADD COLUMN contact_technical_phone TEXT;
|
||||
|
||||
COMMENT ON COLUMN resellers.document IS
|
||||
'CPF/CNPJ livre (sem CHECK de dígito no banco, validado na camada de aplicação) — ao contrário de client_registrations.pj_cnpj/pf_cpf, continua editável via PATCH genérico (decisão deliberada, não replicar a trava de lá aqui).';
|
||||
|
||||
CREATE TABLE reseller_partners (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
reseller_id UUID NOT NULL REFERENCES resellers(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
document TEXT,
|
||||
qualification TEXT,
|
||||
source TEXT NOT NULL DEFAULT 'manual',
|
||||
cpf TEXT,
|
||||
will_sign BOOLEAN NOT NULL DEFAULT false,
|
||||
signature_email TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
COMMENT ON TABLE reseller_partners IS
|
||||
'Sócios/QSA da revenda — mesmo shape de client_registration_partners. source default "manual"; a rota de CNPJ-lookup grava "cnpj_lookup" para os sócios que vierem da API pública.';
|
||||
|
||||
CREATE INDEX idx_reseller_partners_reseller ON reseller_partners(reseller_id);
|
||||
`);
|
||||
};
|
||||
|
||||
exports.down = (pgm) => {
|
||||
pgm.sql(`
|
||||
DROP TABLE IF EXISTS reseller_partners;
|
||||
|
||||
ALTER TABLE resellers
|
||||
DROP COLUMN IF EXISTS trade_name,
|
||||
DROP COLUMN IF EXISTS state_registration,
|
||||
DROP COLUMN IF EXISTS municipal_registration,
|
||||
DROP COLUMN IF EXISTS opening_date,
|
||||
DROP COLUMN IF EXISTS legal_nature,
|
||||
DROP COLUMN IF EXISTS cnpj_situation,
|
||||
DROP COLUMN IF EXISTS main_activity,
|
||||
DROP COLUMN IF EXISTS address_zip,
|
||||
DROP COLUMN IF EXISTS address_street,
|
||||
DROP COLUMN IF EXISTS address_number,
|
||||
DROP COLUMN IF EXISTS address_complement,
|
||||
DROP COLUMN IF EXISTS address_neighborhood,
|
||||
DROP COLUMN IF EXISTS address_city,
|
||||
DROP COLUMN IF EXISTS address_state,
|
||||
DROP COLUMN IF EXISTS address_country,
|
||||
DROP COLUMN IF EXISTS contact_principal_name,
|
||||
DROP COLUMN IF EXISTS contact_principal_email,
|
||||
DROP COLUMN IF EXISTS contact_principal_phone,
|
||||
DROP COLUMN IF EXISTS contact_financial_name,
|
||||
DROP COLUMN IF EXISTS contact_financial_email,
|
||||
DROP COLUMN IF EXISTS contact_financial_phone,
|
||||
DROP COLUMN IF EXISTS contact_technical_name,
|
||||
DROP COLUMN IF EXISTS contact_technical_email,
|
||||
DROP COLUMN IF EXISTS contact_technical_phone;
|
||||
`);
|
||||
};
|
||||
Reference in New Issue
Block a user