.
This commit is contained in:
parent
9f870bbd76
commit
520373cbd6
@ -18,7 +18,6 @@ import {
|
||||
EmailAddress,
|
||||
LanguageCode,
|
||||
Name,
|
||||
Percentage,
|
||||
PhoneNumber,
|
||||
type PostalAddressProps,
|
||||
PostalCode,
|
||||
@ -219,12 +218,9 @@ export class CreateProformaFromFactugesInputMapper
|
||||
);
|
||||
|
||||
const globalDiscountPercentage = extractOrPushError(
|
||||
Percentage.create({
|
||||
value: Number(dto.global_discount_percentage.value),
|
||||
scale: Number(dto.global_discount_percentage.scale),
|
||||
}),
|
||||
"discount_percentage",
|
||||
errors
|
||||
DiscountPercentage.create({ value: Number(dto.global_discount_percentage_value) }),
|
||||
"global_discount_percentage_value",
|
||||
params.errors
|
||||
);
|
||||
|
||||
const languageCode = extractOrPushError(
|
||||
@ -449,28 +445,32 @@ export class CreateProformaFromFactugesInputMapper
|
||||
|
||||
dto.items.forEach((item, index) => {
|
||||
const description = extractOrPushError(
|
||||
maybeFromNullableResult(item.description, (v) => ItemDescription.create(v)),
|
||||
maybeFromNullableResult(item.description, (value) => ItemDescription.create(value)),
|
||||
`items[${index}].description`,
|
||||
params.errors
|
||||
);
|
||||
|
||||
const quantity = extractOrPushError(
|
||||
maybeFromNullableResult(item.quantity_value, (v) => ItemQuantity.create(v)),
|
||||
`items[${index}].quantity`,
|
||||
maybeFromNullableResult(item.quantity_value, (value) =>
|
||||
ItemQuantity.create({ value: Number(value) })
|
||||
),
|
||||
"items[$index].quantity_value",
|
||||
params.errors
|
||||
);
|
||||
|
||||
const unitAmount = extractOrPushError(
|
||||
maybeFromNullableResult(item.unit_value, (v) => ItemAmount.create(v)),
|
||||
`items[${index}].unit_amount`,
|
||||
maybeFromNullableResult(item.unit_value, (value) =>
|
||||
ItemAmount.create({ value: Number(value) })
|
||||
),
|
||||
`items[${index}].unit_value`,
|
||||
params.errors
|
||||
);
|
||||
|
||||
const discountPercentage = extractOrPushError(
|
||||
maybeFromNullableResult(item.discount_percentage_value, (v) =>
|
||||
DiscountPercentage.create(v)
|
||||
maybeFromNullableResult(item.discount_percentage_value, (value) =>
|
||||
DiscountPercentage.create({ value: Number(value) })
|
||||
),
|
||||
`items[${index}].discount_percentage`,
|
||||
`items[${index}].discount_percentage_value`,
|
||||
params.errors
|
||||
);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { NumericStringSchema, PercentageSchema } from "@erp/core";
|
||||
import { NumericStringSchema } from "@erp/core";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const CreateProformaItemFromFactugesRequestSchema = z.object({
|
||||
@ -8,7 +8,6 @@ export const CreateProformaItemFromFactugesRequestSchema = z.object({
|
||||
unit_value: NumericStringSchema.default(""),
|
||||
|
||||
discount_percentage_value: NumericStringSchema.default(""),
|
||||
global_discount_percentage_value: NumericStringSchema.default(""),
|
||||
|
||||
iva_code: z.string().default(""),
|
||||
iva_percentage_value: NumericStringSchema.default(""),
|
||||
@ -64,10 +63,7 @@ export const CreateProformaFromFactugesRequestSchema = z.object({
|
||||
website: z.string(),
|
||||
}),
|
||||
|
||||
global_discount_percentage: PercentageSchema.default({
|
||||
value: "0",
|
||||
scale: "2",
|
||||
}),
|
||||
global_discount_percentage_value: NumericStringSchema.default(""),
|
||||
|
||||
payment_method: z.string().default(""),
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@ import { Maybe, Result, isNullishOrEmpty } from "@repo/rdx-utils";
|
||||
import { MoneyValue, Percentage, Quantity } from "../value-objects";
|
||||
|
||||
/** any | null | undefined -> Maybe<T> usando validación */
|
||||
export function maybeFromNullableResult<T>(
|
||||
input: any,
|
||||
validate: (raw: any) => Result<T>
|
||||
export function maybeFromNullableResult<T, S>(
|
||||
input: S,
|
||||
validate: (raw: S) => Result<T>
|
||||
): Result<Maybe<T>> {
|
||||
if (isNullishOrEmpty(input)) return Result.ok(Maybe.none<T>());
|
||||
const value = validate(input);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user