From 7d61dd75987653a26e7b61ea23b1de5f9422d5c1 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 3 Aug 2026 13:37:36 +0200 Subject: [PATCH] . --- .../validate-request.middleware.ts | 1 + .../mappers/create-proforma-input.mapper.ts | 19 +++++++++++-------- .../models/proforma-create-input.model.ts | 17 ++++++++++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/modules/core/src/api/infrastructure/express/middlewares/validate-request.middleware.ts b/modules/core/src/api/infrastructure/express/middlewares/validate-request.middleware.ts index 7f252db6..85ee00d0 100644 --- a/modules/core/src/api/infrastructure/express/middlewares/validate-request.middleware.ts +++ b/modules/core/src/api/infrastructure/express/middlewares/validate-request.middleware.ts @@ -53,6 +53,7 @@ export const validateRequest = ( const result = schema.safeParse(req[source]); if (!result.success) { + console.debug("ERROR: Validation failed with errors!!"); // Construye errores detallados const validationErrors = result.error.issues.map((err) => ({ field: err.path.join("."), diff --git a/modules/customer-invoices/src/api/application/proformas/mappers/create-proforma-input.mapper.ts b/modules/customer-invoices/src/api/application/proformas/mappers/create-proforma-input.mapper.ts index cdadd6f4..9d0f4398 100644 --- a/modules/customer-invoices/src/api/application/proformas/mappers/create-proforma-input.mapper.ts +++ b/modules/customer-invoices/src/api/application/proformas/mappers/create-proforma-input.mapper.ts @@ -13,21 +13,21 @@ import { } from "@repo/rdx-ddd"; import { Maybe, NumberHelper, Result } from "@repo/rdx-utils"; -import type { CreateProformaRequestDTO } from "../../../../common"; +import type { CreateProformaRequestDTO, TaxCombinationCodeDTO } from "../../../../common"; import { InvoiceSerie, InvoiceStatus, ItemAmount, ItemDescription, ItemQuantity, - type ProformaTaxMode, type ProformaRecipient, + type ProformaTaxMode, } from "../../../domain"; import type { ProformaCreateInputProps, ProformaItemCreateInputProps, - ProformaTaxConfigInputProps, ProformaItemTaxCodesInput, + ProformaTaxConfigInputProps, } from "../models"; export interface ICreateProformaInputMapper { @@ -67,14 +67,16 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper { ); const targetInvoiceSeriesCode = extractOrPushError( - maybeFromNullableResult(dto.target_invoice_series_code, (value) => InvoiceSerie.create(value)), + maybeFromNullableResult(dto.target_invoice_series_code, (value) => + InvoiceSerie.create(value) + ), "target_invoice_series_code", errors ); const proformaDate = extractOrPushError( UtcDate.createFromISO(dto.proforma_date), - "invoice_date", + "proforma_date", errors ); @@ -194,7 +196,9 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper { errors: ValidationErrorDetail[]; } ): ProformaItemCreateInputProps[] { - return itemsDTO.map((item, index) => { + const normalizedItemsDTO = itemsDTO ?? []; + + return normalizedItemsDTO.map((item, index) => { const description = extractOrPushError( maybeFromNullableResult(item.description, (value) => ItemDescription.create(value)), `items[${index}].description`, @@ -248,7 +252,7 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper { } private mapTaxesProps( - taxesDTO: CreateProformaRequestDTO["items"][number]["taxes"], + taxesDTO: TaxCombinationCodeDTO, params: { itemIndex: number; errors: ValidationErrorDetail[] } ): ProformaItemTaxCodesInput { const parts = taxesDTO.split(";"); @@ -365,5 +369,4 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper { throw new ValidationErrorCollection("Proforma props mapping failed", errors); } } - } diff --git a/modules/customer-invoices/src/api/application/proformas/models/proforma-create-input.model.ts b/modules/customer-invoices/src/api/application/proformas/models/proforma-create-input.model.ts index 3c863870..88f0db92 100644 --- a/modules/customer-invoices/src/api/application/proformas/models/proforma-create-input.model.ts +++ b/modules/customer-invoices/src/api/application/proformas/models/proforma-create-input.model.ts @@ -1,6 +1,11 @@ -import type { IProformaCreateProps, IProformaItemCreateProps, ProformaTaxMode } from "../../../domain"; import type { Maybe } from "@repo/rdx-utils"; -import type { InvoiceSerie } from "../../../domain"; + +import type { + IProformaCreateProps, + IProformaItemCreateProps, + InvoiceSerie, + ProformaTaxMode, +} from "../../../domain"; import type { ProformaItemTaxCodesInput } from "./proforma-item-tax-codes-input.model"; @@ -25,7 +30,13 @@ export interface ProformaTaxConfigInputProps { export type ProformaCreateInputProps = Omit< IProformaCreateProps, - "items" | "proformaReference" | "proformaNumber" | "documentSeriesId" | "series" | "taxConfig" + | "items" + | "proformaReference" + | "proformaNumber" + | "documentSeriesId" + | "series" + | "taxConfig" + | "archivedAt" > & { proformaSeriesCode: Maybe; targetInvoiceSeriesCode: Maybe;