feat(api): Quotes, Client Registration e esqueleto de Contratos
Fecha o núcleo comercial da Fase 2/3: motor de precificação de Ofertas (feito diretamente, dado o risco de erro de arredondamento/regra de negócio), Cadastro de Cliente e esqueleto de Contratos (via 2 subagentes em paralelo, salvos manualmente após ambos baterem no limite de gasto mensal da conta — trabalho não commitado nos worktrees foi revisado arquivo a arquivo e copiado para main, com as peças faltantes completadas diretamente). - Quotes: pricing.ts porta as fórmulas do legado (eden.md §7/§8) — needsApproval, faixas de condição de pagamento, efeito legal da fidelidade condicionado a approval_status==='approved'. Fluxo criar→decidir aprovação→fechar negócio (vinculado a um cadastro de cliente, com guarda contra fechamento duplo). - Client Registration: cadastro direto (eden.md §3), MVP autenticado-only (sem token público de autoatendimento, upload ou lookup CNPJ/CEP nesta fase — documentado em comentário). - Contracts: máquina de estados do ADR-0006 imposta via SELECT...FOR UPDATE + tabela de transições, com signed_at/activated_at e histórico de status; 4 das 11 tabelas do ADR-0006 (as demais adiadas). 2 bugs próprios corrigidos antes do commit: UpdateQuoteInput usava COALESCE para campos financeiros (undefined do JS apagaria valor em update parcial) — campos tornados obrigatórios; User.reseller_id/ can_approve_discount faltavam em types.ts apesar das colunas já existirem no banco desde migrations anteriores. Verificado: pnpm turbo run typecheck build (28/28), pnpm test (15/15), e todo o fluxo testado ao vivo via curl contra a stack Docker real, incluindo cenários de erro (transição de status inválida, FK de produto inexistente, fechamento duplo, 401 sem token) e trilha de auditoria conferida no Postgres. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
51
apps/api/src/quotes/dto/update-quote.dto.ts
Normal file
51
apps/api/src/quotes/dto/update-quote.dto.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Type } from "class-transformer";
|
||||
import {
|
||||
ArrayMinSize,
|
||||
IsArray,
|
||||
IsEmail,
|
||||
IsIn,
|
||||
IsInt,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Min,
|
||||
MinLength,
|
||||
ValidateNested,
|
||||
} from "class-validator";
|
||||
import { QuoteItemInputDto } from "./quote-item-input.dto.js";
|
||||
|
||||
/**
|
||||
* Every edit resubmits the full commercial state (contractPeriod, items,
|
||||
* etc.) rather than a sparse patch — the service always recomputes the
|
||||
* entire pricing picture together (pricing.ts), so a partial edit that
|
||||
* only touched `notes` would still need the rest of the state to
|
||||
* recompute against; simplest and safest is to require it every time,
|
||||
* matching how the legacy's own edit screen always resubmits the whole
|
||||
* form. `resellerId` is intentionally absent — not changeable post-creation.
|
||||
*/
|
||||
export class UpdateQuoteDto {
|
||||
@IsOptional() @IsString() clientName?: string;
|
||||
@IsOptional() @IsString() clientCompany?: string;
|
||||
@IsOptional() @IsEmail() clientEmail?: string;
|
||||
@IsOptional() @IsString() clientPhone?: string;
|
||||
|
||||
@IsIn([0, 12, 24, 36, 48])
|
||||
contractPeriod!: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
fidelityPeriod?: number;
|
||||
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => QuoteItemInputDto)
|
||||
items!: QuoteItemInputDto[];
|
||||
|
||||
@IsOptional() @IsNumber() @Min(0) implGeral?: number;
|
||||
@IsOptional() @IsNumber() @Min(0.01) proposedMonthlyTotal?: number;
|
||||
|
||||
@IsOptional() @IsIn(["À vista", "1+1", "1+2"]) implPaymentCondition?: string;
|
||||
@IsOptional() @IsString() @MinLength(0) notes?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user