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