.
This commit is contained in:
parent
71030522ed
commit
7d61dd7598
@ -53,6 +53,7 @@ export const validateRequest = <T extends "body" | "query" | "params">(
|
|||||||
const result = schema.safeParse(req[source]);
|
const result = schema.safeParse(req[source]);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
console.debug("ERROR: Validation failed with errors!!");
|
||||||
// Construye errores detallados
|
// Construye errores detallados
|
||||||
const validationErrors = result.error.issues.map((err) => ({
|
const validationErrors = result.error.issues.map((err) => ({
|
||||||
field: err.path.join("."),
|
field: err.path.join("."),
|
||||||
|
|||||||
@ -13,21 +13,21 @@ import {
|
|||||||
} from "@repo/rdx-ddd";
|
} from "@repo/rdx-ddd";
|
||||||
import { Maybe, NumberHelper, Result } from "@repo/rdx-utils";
|
import { Maybe, NumberHelper, Result } from "@repo/rdx-utils";
|
||||||
|
|
||||||
import type { CreateProformaRequestDTO } from "../../../../common";
|
import type { CreateProformaRequestDTO, TaxCombinationCodeDTO } from "../../../../common";
|
||||||
import {
|
import {
|
||||||
InvoiceSerie,
|
InvoiceSerie,
|
||||||
InvoiceStatus,
|
InvoiceStatus,
|
||||||
ItemAmount,
|
ItemAmount,
|
||||||
ItemDescription,
|
ItemDescription,
|
||||||
ItemQuantity,
|
ItemQuantity,
|
||||||
type ProformaTaxMode,
|
|
||||||
type ProformaRecipient,
|
type ProformaRecipient,
|
||||||
|
type ProformaTaxMode,
|
||||||
} from "../../../domain";
|
} from "../../../domain";
|
||||||
import type {
|
import type {
|
||||||
ProformaCreateInputProps,
|
ProformaCreateInputProps,
|
||||||
ProformaItemCreateInputProps,
|
ProformaItemCreateInputProps,
|
||||||
ProformaTaxConfigInputProps,
|
|
||||||
ProformaItemTaxCodesInput,
|
ProformaItemTaxCodesInput,
|
||||||
|
ProformaTaxConfigInputProps,
|
||||||
} from "../models";
|
} from "../models";
|
||||||
|
|
||||||
export interface ICreateProformaInputMapper {
|
export interface ICreateProformaInputMapper {
|
||||||
@ -67,14 +67,16 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const targetInvoiceSeriesCode = extractOrPushError(
|
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",
|
"target_invoice_series_code",
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|
||||||
const proformaDate = extractOrPushError(
|
const proformaDate = extractOrPushError(
|
||||||
UtcDate.createFromISO(dto.proforma_date),
|
UtcDate.createFromISO(dto.proforma_date),
|
||||||
"invoice_date",
|
"proforma_date",
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -194,7 +196,9 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper {
|
|||||||
errors: ValidationErrorDetail[];
|
errors: ValidationErrorDetail[];
|
||||||
}
|
}
|
||||||
): ProformaItemCreateInputProps[] {
|
): ProformaItemCreateInputProps[] {
|
||||||
return itemsDTO.map((item, index) => {
|
const normalizedItemsDTO = itemsDTO ?? [];
|
||||||
|
|
||||||
|
return normalizedItemsDTO.map((item, index) => {
|
||||||
const description = extractOrPushError(
|
const description = extractOrPushError(
|
||||||
maybeFromNullableResult(item.description, (value) => ItemDescription.create(value)),
|
maybeFromNullableResult(item.description, (value) => ItemDescription.create(value)),
|
||||||
`items[${index}].description`,
|
`items[${index}].description`,
|
||||||
@ -248,7 +252,7 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private mapTaxesProps(
|
private mapTaxesProps(
|
||||||
taxesDTO: CreateProformaRequestDTO["items"][number]["taxes"],
|
taxesDTO: TaxCombinationCodeDTO,
|
||||||
params: { itemIndex: number; errors: ValidationErrorDetail[] }
|
params: { itemIndex: number; errors: ValidationErrorDetail[] }
|
||||||
): ProformaItemTaxCodesInput {
|
): ProformaItemTaxCodesInput {
|
||||||
const parts = taxesDTO.split(";");
|
const parts = taxesDTO.split(";");
|
||||||
@ -365,5 +369,4 @@ export class CreateProformaInputMapper implements ICreateProformaInputMapper {
|
|||||||
throw new ValidationErrorCollection("Proforma props mapping failed", errors);
|
throw new ValidationErrorCollection("Proforma props mapping failed", errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
import type { IProformaCreateProps, IProformaItemCreateProps, ProformaTaxMode } from "../../../domain";
|
|
||||||
import type { Maybe } from "@repo/rdx-utils";
|
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";
|
import type { ProformaItemTaxCodesInput } from "./proforma-item-tax-codes-input.model";
|
||||||
|
|
||||||
@ -25,7 +30,13 @@ export interface ProformaTaxConfigInputProps {
|
|||||||
|
|
||||||
export type ProformaCreateInputProps = Omit<
|
export type ProformaCreateInputProps = Omit<
|
||||||
IProformaCreateProps,
|
IProformaCreateProps,
|
||||||
"items" | "proformaReference" | "proformaNumber" | "documentSeriesId" | "series" | "taxConfig"
|
| "items"
|
||||||
|
| "proformaReference"
|
||||||
|
| "proformaNumber"
|
||||||
|
| "documentSeriesId"
|
||||||
|
| "series"
|
||||||
|
| "taxConfig"
|
||||||
|
| "archivedAt"
|
||||||
> & {
|
> & {
|
||||||
proformaSeriesCode: Maybe<InvoiceSerie>;
|
proformaSeriesCode: Maybe<InvoiceSerie>;
|
||||||
targetInvoiceSeriesCode: Maybe<InvoiceSerie>;
|
targetInvoiceSeriesCode: Maybe<InvoiceSerie>;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user