This commit is contained in:
David Arranz 2026-08-03 13:37:36 +02:00
parent 71030522ed
commit 7d61dd7598
3 changed files with 26 additions and 11 deletions

View File

@ -53,6 +53,7 @@ export const validateRequest = <T extends "body" | "query" | "params">(
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("."),

View File

@ -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);
}
}
}

View File

@ -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<InvoiceSerie>;
targetInvoiceSeriesCode: Maybe<InvoiceSerie>;