Facturas de cliente
This commit is contained in:
parent
e719feaadf
commit
e9e0ce5406
@ -8,7 +8,6 @@ import {
|
|||||||
toNullable,
|
toNullable,
|
||||||
} from "@repo/rdx-ddd";
|
} from "@repo/rdx-ddd";
|
||||||
import { Result } from "@repo/rdx-utils";
|
import { Result } from "@repo/rdx-utils";
|
||||||
import { InferCreationAttributes } from "sequelize";
|
|
||||||
import {
|
import {
|
||||||
CustomerInvoice,
|
CustomerInvoice,
|
||||||
CustomerInvoiceItem,
|
CustomerInvoiceItem,
|
||||||
@ -62,15 +61,13 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
);
|
);
|
||||||
|
|
||||||
const description = extractOrPushError(
|
const description = extractOrPushError(
|
||||||
maybeFromNullableVO(source.description, (value) =>
|
maybeFromNullableVO(source.description, (v) => CustomerInvoiceItemDescription.create(v)),
|
||||||
CustomerInvoiceItemDescription.create(value)
|
|
||||||
),
|
|
||||||
`items[${index}].description`,
|
`items[${index}].description`,
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|
||||||
const quantity = extractOrPushError(
|
const quantity = extractOrPushError(
|
||||||
maybeFromNullableVO(source.quantity_value, (value) => ItemQuantity.create({ value })),
|
maybeFromNullableVO(source.quantity_value, (v) => ItemQuantity.create({ value: v })),
|
||||||
`items[${index}].quantity`,
|
`items[${index}].quantity`,
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
@ -84,8 +81,8 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
);
|
);
|
||||||
|
|
||||||
const discountPercentage = extractOrPushError(
|
const discountPercentage = extractOrPushError(
|
||||||
maybeFromNullableVO(source.discount_percentage_value, (value) =>
|
maybeFromNullableVO(source.discount_percentage_value, (v) =>
|
||||||
ItemDiscount.create({ value })
|
ItemDiscount.create({ value: v })
|
||||||
),
|
),
|
||||||
`items[${index}].discount_percentage`,
|
`items[${index}].discount_percentage`,
|
||||||
errors
|
errors
|
||||||
@ -107,9 +104,8 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
source: CustomerInvoiceItemModel,
|
source: CustomerInvoiceItemModel,
|
||||||
params?: MapperParamsType
|
params?: MapperParamsType
|
||||||
): Result<CustomerInvoiceItem, Error> {
|
): Result<CustomerInvoiceItem, Error> {
|
||||||
const { errors, index, requireIncludes } = params as {
|
const { errors, index } = params as {
|
||||||
index: number;
|
index: number;
|
||||||
requireIncludes: boolean;
|
|
||||||
errors: ValidationErrorDetail[];
|
errors: ValidationErrorDetail[];
|
||||||
attributes: Partial<CustomerInvoiceProps>;
|
attributes: Partial<CustomerInvoiceProps>;
|
||||||
};
|
};
|
||||||
@ -117,17 +113,7 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
// 1) Valores escalares (atributos generales)
|
// 1) Valores escalares (atributos generales)
|
||||||
const attributes = this.mapAttributesToDomain(source, params);
|
const attributes = this.mapAttributesToDomain(source, params);
|
||||||
|
|
||||||
// 2) Comprobar relaciones
|
// 2) Taxes (colección a nivel de item/línea)
|
||||||
if (requireIncludes) {
|
|
||||||
if (!source.taxes) {
|
|
||||||
errors.push({
|
|
||||||
path: `items[${index}].taxes`,
|
|
||||||
message: "Taxes not included in query (requireIncludes=true)",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3) Taxes (colección a nivel de item/línea)
|
|
||||||
const taxesResults = this._taxesMapper.mapToDomainCollection(
|
const taxesResults = this._taxesMapper.mapToDomainCollection(
|
||||||
source.taxes,
|
source.taxes,
|
||||||
source.taxes.length,
|
source.taxes.length,
|
||||||
@ -144,10 +130,9 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5) Construcción del elemento de dominio
|
|
||||||
|
|
||||||
const taxes = ItemTaxes.create(taxesResults.data.getAll());
|
const taxes = ItemTaxes.create(taxesResults.data.getAll());
|
||||||
|
|
||||||
|
// 3) Construcción del elemento de dominio
|
||||||
const createResult = CustomerInvoiceItem.create(
|
const createResult = CustomerInvoiceItem.create(
|
||||||
{
|
{
|
||||||
languageCode: attributes.languageCode!,
|
languageCode: attributes.languageCode!,
|
||||||
@ -175,7 +160,7 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
public mapToPersistence(
|
public mapToPersistence(
|
||||||
source: CustomerInvoiceItem,
|
source: CustomerInvoiceItem,
|
||||||
params?: MapperParamsType
|
params?: MapperParamsType
|
||||||
): Result<InferCreationAttributes<CustomerInvoiceItemModel, {}>, Error> {
|
): Result<CustomerInvoiceItemCreationAttributes, Error> {
|
||||||
const { errors, index, parent } = params as {
|
const { errors, index, parent } = params as {
|
||||||
index: number;
|
index: number;
|
||||||
parent: CustomerInvoice;
|
parent: CustomerInvoice;
|
||||||
@ -201,10 +186,12 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
description: toNullable(source.description, (v) => v.toPrimitive()),
|
description: toNullable(source.description, (v) => v.toPrimitive()),
|
||||||
|
|
||||||
quantity_value: toNullable(source.quantity, (v) => v.toPrimitive().value),
|
quantity_value: toNullable(source.quantity, (v) => v.toPrimitive().value),
|
||||||
quantity_scale: toNullable(source.quantity, (v) => v.toPrimitive().scale),
|
quantity_scale:
|
||||||
|
toNullable(source.quantity, (v) => v.toPrimitive().scale) ?? ItemQuantity.DEFAULT_SCALE,
|
||||||
|
|
||||||
unit_amount_value: toNullable(source.unitAmount, (v) => v.toPrimitive().value),
|
unit_amount_value: toNullable(source.unitAmount, (v) => v.toPrimitive().value),
|
||||||
unit_amount_scale: toNullable(source.unitAmount, (v) => v.toPrimitive().scale),
|
unit_amount_scale:
|
||||||
|
toNullable(source.unitAmount, (v) => v.toPrimitive().scale) ?? ItemAmount.DEFAULT_SCALE,
|
||||||
|
|
||||||
subtotal_amount_value: allAmounts.subtotalAmount.value,
|
subtotal_amount_value: allAmounts.subtotalAmount.value,
|
||||||
subtotal_amount_scale: allAmounts.subtotalAmount.scale,
|
subtotal_amount_scale: allAmounts.subtotalAmount.scale,
|
||||||
@ -213,10 +200,9 @@ export class CustomerInvoiceItemDomainMapper
|
|||||||
source.discountPercentage,
|
source.discountPercentage,
|
||||||
(v) => v.toPrimitive().value
|
(v) => v.toPrimitive().value
|
||||||
),
|
),
|
||||||
discount_percentage_scale: toNullable(
|
discount_percentage_scale:
|
||||||
source.discountPercentage,
|
toNullable(source.discountPercentage, (v) => v.toPrimitive().scale) ??
|
||||||
(v) => v.toPrimitive().scale
|
ItemDiscount.DEFAULT_SCALE,
|
||||||
),
|
|
||||||
|
|
||||||
discount_amount_value: allAmounts.discountAmount.value,
|
discount_amount_value: allAmounts.discountAmount.value,
|
||||||
discount_amount_scale: allAmounts.discountAmount.scale,
|
discount_amount_scale: allAmounts.discountAmount.scale,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import {
|
|||||||
maybeFromNullableVO,
|
maybeFromNullableVO,
|
||||||
toNullable,
|
toNullable,
|
||||||
} from "@repo/rdx-ddd";
|
} from "@repo/rdx-ddd";
|
||||||
import { Collection, Maybe, Result } from "@repo/rdx-utils";
|
import { Collection, Maybe, Result, isNullishOrEmpty } from "@repo/rdx-utils";
|
||||||
import {
|
import {
|
||||||
CustomerInvoice,
|
CustomerInvoice,
|
||||||
CustomerInvoiceItems,
|
CustomerInvoiceItems,
|
||||||
@ -23,9 +23,9 @@ import {
|
|||||||
InvoicePaymentMethod,
|
InvoicePaymentMethod,
|
||||||
} from "../../../domain";
|
} from "../../../domain";
|
||||||
import { CustomerInvoiceCreationAttributes, CustomerInvoiceModel } from "../../sequelize";
|
import { CustomerInvoiceCreationAttributes, CustomerInvoiceModel } from "../../sequelize";
|
||||||
import { CustomerInvoiceItemDomainMapper as CustomerInvoiceItemFullMapper } from "./customer-invoice-item.mapper";
|
import { CustomerInvoiceItemDomainMapper } from "./customer-invoice-item.mapper";
|
||||||
import { InvoiceRecipientDomainMapper as InvoiceRecipientFullMapper } from "./invoice-recipient.mapper";
|
import { InvoiceRecipientDomainMapper } from "./invoice-recipient.mapper";
|
||||||
import { TaxesDomainMapper as TaxesFullMapper } from "./invoice-taxes.mapper";
|
import { TaxesDomainMapper } from "./invoice-taxes.mapper";
|
||||||
|
|
||||||
export interface ICustomerInvoiceDomainMapper
|
export interface ICustomerInvoiceDomainMapper
|
||||||
extends ISequelizeDomainMapper<
|
extends ISequelizeDomainMapper<
|
||||||
@ -42,59 +42,16 @@ export class CustomerInvoiceDomainMapper
|
|||||||
>
|
>
|
||||||
implements ICustomerInvoiceDomainMapper
|
implements ICustomerInvoiceDomainMapper
|
||||||
{
|
{
|
||||||
private _itemsMapper: CustomerInvoiceItemFullMapper;
|
private _itemsMapper: CustomerInvoiceItemDomainMapper;
|
||||||
private _recipientMapper: InvoiceRecipientFullMapper;
|
private _recipientMapper: InvoiceRecipientDomainMapper;
|
||||||
private _taxesMapper: TaxesFullMapper;
|
private _taxesMapper: TaxesDomainMapper;
|
||||||
|
|
||||||
constructor(params: MapperParamsType) {
|
constructor(params: MapperParamsType) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._itemsMapper = new CustomerInvoiceItemFullMapper(params); // Instanciar el mapper de items
|
this._itemsMapper = new CustomerInvoiceItemDomainMapper(params); // Instanciar el mapper de items
|
||||||
this._recipientMapper = new InvoiceRecipientFullMapper();
|
this._recipientMapper = new InvoiceRecipientDomainMapper();
|
||||||
this._taxesMapper = new TaxesFullMapper(params);
|
this._taxesMapper = new TaxesDomainMapper(params);
|
||||||
}
|
|
||||||
|
|
||||||
private _mapPaymentMethodToDomain(source: CustomerInvoiceModel, params?: MapperParamsType) {
|
|
||||||
const { errors } = params as {
|
|
||||||
errors: ValidationErrorDetail[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const paymentId = extractOrPushError(
|
|
||||||
maybeFromNullableVO(source.payment_method_id, (value) => UniqueID.create(value)),
|
|
||||||
"payment_method_id",
|
|
||||||
errors
|
|
||||||
);
|
|
||||||
|
|
||||||
const paymentDescription = extractOrPushError(
|
|
||||||
maybeFromNullableVO(source.payment_method_description, (value) => Result.ok(String(value))),
|
|
||||||
"payment_method_description",
|
|
||||||
errors
|
|
||||||
);
|
|
||||||
|
|
||||||
if (errors.length > 0) {
|
|
||||||
return Result.fail(new ValidationErrorCollection("Invoice payment mapping failed", errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paymentDescription!.isNone() || paymentId!.isNone()) {
|
|
||||||
return Result.ok(Maybe.none<InvoicePaymentMethod>());
|
|
||||||
}
|
|
||||||
|
|
||||||
const paymentResult = InvoicePaymentMethod.create(
|
|
||||||
{
|
|
||||||
paymentDescription: paymentDescription?.getOrUndefined()!,
|
|
||||||
},
|
|
||||||
paymentId?.getOrUndefined()!
|
|
||||||
);
|
|
||||||
|
|
||||||
if (paymentResult.isFailure) {
|
|
||||||
return Result.fail(
|
|
||||||
new ValidationErrorCollection("Invoice payment method creation failed", [
|
|
||||||
{ path: "paymentMethod", message: paymentResult.error.message },
|
|
||||||
])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.ok(Maybe.some<InvoicePaymentMethod>(paymentResult.data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _mapAttributesToDomain(source: CustomerInvoiceModel, params?: MapperParamsType) {
|
private _mapAttributesToDomain(source: CustomerInvoiceModel, params?: MapperParamsType) {
|
||||||
@ -120,17 +77,18 @@ export class CustomerInvoiceDomainMapper
|
|||||||
);
|
);
|
||||||
|
|
||||||
const series = extractOrPushError(
|
const series = extractOrPushError(
|
||||||
maybeFromNullableVO(source.series, (value) => CustomerInvoiceSerie.create(value)),
|
maybeFromNullableVO(source.series, (v) => CustomerInvoiceSerie.create(v)),
|
||||||
"serie",
|
"series",
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|
||||||
const invoiceNumber = extractOrPushError(
|
const invoiceNumber = extractOrPushError(
|
||||||
maybeFromNullableVO(source.invoice_number, (value) => CustomerInvoiceNumber.create(value)),
|
maybeFromNullableVO(source.invoice_number, (v) => CustomerInvoiceNumber.create(v)),
|
||||||
"invoice_number",
|
"invoice_number",
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Fechas
|
||||||
const invoiceDate = extractOrPushError(
|
const invoiceDate = extractOrPushError(
|
||||||
UtcDate.createFromISO(source.invoice_date),
|
UtcDate.createFromISO(source.invoice_date),
|
||||||
"invoice_date",
|
"invoice_date",
|
||||||
@ -138,11 +96,25 @@ export class CustomerInvoiceDomainMapper
|
|||||||
);
|
);
|
||||||
|
|
||||||
const operationDate = extractOrPushError(
|
const operationDate = extractOrPushError(
|
||||||
maybeFromNullableVO(source.operation_date, (value) => UtcDate.createFromISO(value)),
|
maybeFromNullableVO(source.operation_date, (v) => UtcDate.createFromISO(v)),
|
||||||
"operation_date",
|
"operation_date",
|
||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Idioma / divisa
|
||||||
|
const languageCode = extractOrPushError(
|
||||||
|
LanguageCode.create(source.language_code),
|
||||||
|
"language_code",
|
||||||
|
errors
|
||||||
|
);
|
||||||
|
|
||||||
|
const currencyCode = extractOrPushError(
|
||||||
|
CurrencyCode.create(source.currency_code),
|
||||||
|
"currency_code",
|
||||||
|
errors
|
||||||
|
);
|
||||||
|
|
||||||
|
// Textos opcionales
|
||||||
const reference = extractOrPushError(
|
const reference = extractOrPushError(
|
||||||
maybeFromNullableVO(source.reference, (value) => Result.ok(String(value))),
|
maybeFromNullableVO(source.reference, (value) => Result.ok(String(value))),
|
||||||
"reference",
|
"reference",
|
||||||
@ -161,22 +133,35 @@ export class CustomerInvoiceDomainMapper
|
|||||||
errors
|
errors
|
||||||
);
|
);
|
||||||
|
|
||||||
const languageCode = extractOrPushError(
|
// Método de pago (VO opcional con id + descripción)
|
||||||
LanguageCode.create(source.language_code),
|
let paymentMethod = Maybe.none<InvoicePaymentMethod>();
|
||||||
"language_code",
|
|
||||||
errors
|
|
||||||
);
|
|
||||||
|
|
||||||
const currencyCode = extractOrPushError(
|
if (!isNullishOrEmpty(source.payment_method_id)) {
|
||||||
CurrencyCode.create(source.currency_code),
|
const paymentId = extractOrPushError(
|
||||||
"currency_code",
|
UniqueID.create(String(source.payment_method_id)),
|
||||||
errors
|
"paymentMethod.id",
|
||||||
);
|
errors
|
||||||
|
);
|
||||||
|
|
||||||
|
const paymentVO = extractOrPushError(
|
||||||
|
InvoicePaymentMethod.create(
|
||||||
|
{ paymentDescription: String(source.payment_method_description ?? "") },
|
||||||
|
paymentId ?? undefined
|
||||||
|
),
|
||||||
|
"payment_method_description",
|
||||||
|
errors
|
||||||
|
);
|
||||||
|
|
||||||
|
if (paymentVO) {
|
||||||
|
paymentMethod = Maybe.some(paymentVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// % descuento (VO)
|
||||||
const discountPercentage = extractOrPushError(
|
const discountPercentage = extractOrPushError(
|
||||||
Percentage.create({
|
Percentage.create({
|
||||||
value: source.discount_percentage_value,
|
value: Number(source.discount_percentage_value ?? 0),
|
||||||
scale: source.discount_percentage_scale,
|
scale: Number(source.discount_percentage_scale ?? 2),
|
||||||
}),
|
}),
|
||||||
"discount_percentage_value",
|
"discount_percentage_value",
|
||||||
errors
|
errors
|
||||||
@ -198,6 +183,7 @@ export class CustomerInvoiceDomainMapper
|
|||||||
languageCode,
|
languageCode,
|
||||||
currencyCode,
|
currencyCode,
|
||||||
discountPercentage,
|
discountPercentage,
|
||||||
|
paymentMethod,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,33 +230,8 @@ export class CustomerInvoiceDomainMapper
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4) Taxes (colección a nivel factura)
|
// Nota: los impuestos a nivel factura (tabla customer_invoice_taxes) se derivan de los items.
|
||||||
const taxesResults = this._taxesMapper.mapToDomainCollection(
|
// El agregado expone un getter `taxes` (derivado). No se incluye en las props.
|
||||||
source.taxes,
|
|
||||||
source.taxes.length,
|
|
||||||
{
|
|
||||||
errors,
|
|
||||||
attributes,
|
|
||||||
...params,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (taxesResults.isFailure) {
|
|
||||||
errors.push({
|
|
||||||
path: "taxes",
|
|
||||||
message: taxesResults.error.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Payment method
|
|
||||||
const paymentMethodResult = this._mapPaymentMethodToDomain(source, { errors, ...params });
|
|
||||||
|
|
||||||
if (paymentMethodResult.isFailure) {
|
|
||||||
errors.push({
|
|
||||||
path: "paymentMethod",
|
|
||||||
message: paymentMethodResult.error.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5) Si hubo errores de mapeo, devolvemos colección de validación
|
// 5) Si hubo errores de mapeo, devolvemos colección de validación
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
@ -280,7 +241,6 @@ export class CustomerInvoiceDomainMapper
|
|||||||
// 6) Construcción del agregado (Dominio)
|
// 6) Construcción del agregado (Dominio)
|
||||||
|
|
||||||
const recipient = recipientResult.data;
|
const recipient = recipientResult.data;
|
||||||
const paymentMethod = paymentMethodResult.data;
|
|
||||||
|
|
||||||
const items = CustomerInvoiceItems.create({
|
const items = CustomerInvoiceItems.create({
|
||||||
languageCode: attributes.languageCode!,
|
languageCode: attributes.languageCode!,
|
||||||
@ -310,7 +270,7 @@ export class CustomerInvoiceDomainMapper
|
|||||||
|
|
||||||
discountPercentage: attributes.discountPercentage!,
|
discountPercentage: attributes.discountPercentage!,
|
||||||
|
|
||||||
paymentMethod: paymentMethod!,
|
paymentMethod: attributes.paymentMethod!,
|
||||||
|
|
||||||
items,
|
items,
|
||||||
};
|
};
|
||||||
@ -350,7 +310,7 @@ export class CustomerInvoiceDomainMapper
|
|||||||
|
|
||||||
const items = itemsResult.data;
|
const items = itemsResult.data;
|
||||||
|
|
||||||
// 1) Taxes
|
// 2) Taxes
|
||||||
|
|
||||||
const taxesResult = this._taxesMapper.mapToPersistenceArray(new Collection(source.taxes), {
|
const taxesResult = this._taxesMapper.mapToPersistenceArray(new Collection(source.taxes), {
|
||||||
errors,
|
errors,
|
||||||
@ -378,31 +338,28 @@ export class CustomerInvoiceDomainMapper
|
|||||||
|
|
||||||
// 7) Si hubo errores de mapeo, devolvemos colección de validación
|
// 7) Si hubo errores de mapeo, devolvemos colección de validación
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return Result.fail(
|
return Result.fail(new ValidationErrorCollection(errors));
|
||||||
new ValidationErrorCollection("Customer invoice mapping to persistence failed", errors)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoiceValues: CustomerInvoiceCreationAttributes = {
|
const invoiceValues: CustomerInvoiceCreationAttributes = {
|
||||||
|
// Identificación
|
||||||
id: source.id.toPrimitive(),
|
id: source.id.toPrimitive(),
|
||||||
company_id: source.companyId.toPrimitive(),
|
company_id: source.companyId.toPrimitive(),
|
||||||
|
|
||||||
|
// Flags / estado / serie / número
|
||||||
is_proforma: source.isProforma,
|
is_proforma: source.isProforma,
|
||||||
status: source.status.toPrimitive(),
|
status: source.status.toPrimitive(),
|
||||||
series: toNullable(source.series, (series) => series.toPrimitive()),
|
series: toNullable(source.series, (v) => v.toPrimitive()),
|
||||||
invoice_number: toNullable(source.invoiceNumber, (invoiceNumber) =>
|
invoice_number: toNullable(source.invoiceNumber, (v) => v.toPrimitive()),
|
||||||
invoiceNumber.toPrimitive()
|
|
||||||
),
|
|
||||||
invoice_date: source.invoiceDate.toPrimitive(),
|
invoice_date: source.invoiceDate.toPrimitive(),
|
||||||
operation_date: toNullable(source.operationDate, (operationDate) =>
|
operation_date: toNullable(source.operationDate, (v) => v.toPrimitive()),
|
||||||
operationDate.toPrimitive()
|
|
||||||
),
|
|
||||||
language_code: source.languageCode.toPrimitive(),
|
language_code: source.languageCode.toPrimitive(),
|
||||||
currency_code: source.currencyCode.toPrimitive(),
|
currency_code: source.currencyCode.toPrimitive(),
|
||||||
|
|
||||||
reference: toNullable(source.reference, (reference) => reference),
|
reference: toNullable(source.reference, (reference) => reference),
|
||||||
description: toNullable(source.description, (description) => description),
|
description: toNullable(source.description, (description) => description),
|
||||||
notes: toNullable(source.notes, (notes) => notes.toPrimitive()),
|
notes: toNullable(source.notes, (v) => v.toPrimitive()),
|
||||||
|
|
||||||
subtotal_amount_value: allAmounts.subtotalAmount.value,
|
subtotal_amount_value: allAmounts.subtotalAmount.value,
|
||||||
subtotal_amount_scale: allAmounts.subtotalAmount.scale,
|
subtotal_amount_scale: allAmounts.subtotalAmount.scale,
|
||||||
@ -430,6 +387,7 @@ export class CustomerInvoiceDomainMapper
|
|||||||
|
|
||||||
customer_id: source.customerId.toPrimitive(),
|
customer_id: source.customerId.toPrimitive(),
|
||||||
...recipient,
|
...recipient,
|
||||||
|
|
||||||
taxes,
|
taxes,
|
||||||
items,
|
items,
|
||||||
};
|
};
|
||||||
@ -442,9 +400,10 @@ export class CustomerInvoiceDomainMapper
|
|||||||
errors: ValidationErrorDetail[];
|
errors: ValidationErrorDetail[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const recipient = source.recipient.getOrUndefined();
|
const hasRecipient = source.hasRecipient;
|
||||||
|
const recipient = source.recipient!.getOrUndefined();
|
||||||
|
|
||||||
if (!source.isProforma && !recipient) {
|
if (!source.isProforma && !hasRecipient) {
|
||||||
errors.push({
|
errors.push({
|
||||||
path: "recipient",
|
path: "recipient",
|
||||||
message: "[CustomerInvoiceDomainMapper] Issued customer invoice w/o recipient data",
|
message: "[CustomerInvoiceDomainMapper] Issued customer invoice w/o recipient data",
|
||||||
|
|||||||
@ -106,9 +106,7 @@ export class InvoiceRecipientDomainMapper {
|
|||||||
|
|
||||||
if (createResult.isFailure) {
|
if (createResult.isFailure) {
|
||||||
return Result.fail(
|
return Result.fail(
|
||||||
new ValidationErrorCollection("Invoice recipient entity creation failed", [
|
new ValidationErrorCollection([{ path: "recipient", message: createResult.error.message }])
|
||||||
{ path: "recipient", message: createResult.error.message },
|
|
||||||
])
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,7 +68,7 @@ export class ItemTaxesDomainMapper
|
|||||||
const createResult = Tax.create(tax!);
|
const createResult = Tax.create(tax!);
|
||||||
if (createResult.isFailure) {
|
if (createResult.isFailure) {
|
||||||
return Result.fail(
|
return Result.fail(
|
||||||
new ValidationErrorCollection("Invoice item tax creation failed", [
|
new ValidationErrorCollection([
|
||||||
{ path: `taxes[${index}]`, message: createResult.error.message },
|
{ path: `taxes[${index}]`, message: createResult.error.message },
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user