This commit is contained in:
David Arranz 2025-09-30 13:57:21 +02:00
parent 35e261e80d
commit ae6afd2c28
6 changed files with 39 additions and 8 deletions

View File

@ -33,12 +33,12 @@ export function mapDTOToCustomerInvoiceProps(dto: CreateCustomerInvoiceRequestDT
const invoiceId = extractOrPushError(UniqueID.create(dto.id), "id", errors); const invoiceId = extractOrPushError(UniqueID.create(dto.id), "id", errors);
const invoiceNumber = extractOrPushError( const invoiceNumber = extractOrPushError(
CustomerInvoiceNumber.create(dto.invoice_number), maybeFromNullableVO(dto.invoice_number, (value) => CustomerInvoiceNumber.create(value)),
"invoice_number", "invoice_number",
errors errors
); );
const invoiceSeries = extractOrPushError( const invoiceSeries = extractOrPushError(
maybeFromNullableVO(dto.invoice_series, (value) => CustomerInvoiceSerie.create(value)), maybeFromNullableVO(dto.series, (value) => CustomerInvoiceSerie.create(value)),
"invoice_series", "invoice_series",
errors errors
); );

View File

@ -14,7 +14,7 @@ export class ListCustomerInvoicesPresenter extends Presenter {
company_id: invoice.companyId.toString(), company_id: invoice.companyId.toString(),
customer_id: invoice.customerId.toString(), customer_id: invoice.customerId.toString(),
invoice_number: invoice.invoiceNumber.toString(), invoice_number: toEmptyString(invoice.invoiceNumber, (value) => value.toString()),
status: invoice.status.toPrimitive(), status: invoice.status.toPrimitive(),
series: toEmptyString(invoice.series, (value) => value.toString()), series: toEmptyString(invoice.series, (value) => value.toString()),

View File

@ -34,6 +34,7 @@ export interface CustomerInvoiceProps {
recipient: Maybe<InvoiceRecipient>; recipient: Maybe<InvoiceRecipient>;
reference: Maybe<string>; reference: Maybe<string>;
description: Maybe<string>;
notes: Maybe<TextValue>; notes: Maybe<TextValue>;
languageCode: LanguageCode; languageCode: LanguageCode;
@ -144,6 +145,10 @@ export class CustomerInvoice
return this.props.reference; return this.props.reference;
} }
public get description(): Maybe<string> {
return this.props.description;
}
public get notes(): Maybe<TextValue> { public get notes(): Maybe<TextValue> {
return this.props.notes; return this.props.notes;
} }

View File

@ -149,6 +149,12 @@ export class CustomerInvoiceDomainMapper
errors errors
); );
const description = extractOrPushError(
maybeFromNullableVO(source.description, (value) => Result.ok(String(value))),
"description",
errors
);
const notes = extractOrPushError( const notes = extractOrPushError(
maybeFromNullableVO(source.notes, (value) => TextValue.create(value)), maybeFromNullableVO(source.notes, (value) => TextValue.create(value)),
"notes", "notes",
@ -187,6 +193,7 @@ export class CustomerInvoiceDomainMapper
invoiceDate, invoiceDate,
operationDate, operationDate,
reference, reference,
description,
notes, notes,
languageCode, languageCode,
currencyCode, currencyCode,
@ -267,7 +274,9 @@ export class CustomerInvoiceDomainMapper
// 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) {
return Result.fail(new ValidationErrorCollection("Customer mapping failed", errors)); return Result.fail(
new ValidationErrorCollection("Customer invoice mapping failed [mapToDomain]", errors)
);
} }
// 6) Construcción del agregado (Dominio) // 6) Construcción del agregado (Dominio)
@ -295,6 +304,7 @@ export class CustomerInvoiceDomainMapper
recipient: recipient, recipient: recipient,
reference: attributes.reference!, reference: attributes.reference!,
description: attributes.description!,
notes: attributes.notes!, notes: attributes.notes!,
languageCode: attributes.languageCode!, languageCode: attributes.languageCode!,
@ -391,6 +401,7 @@ export class CustomerInvoiceDomainMapper
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),
notes: toNullable(source.notes, (notes) => notes.toPrimitive()), notes: toNullable(source.notes, (notes) => notes.toPrimitive()),
subtotal_amount_value: allAmounts.subtotalAmount.value, subtotal_amount_value: allAmounts.subtotalAmount.value,

View File

@ -31,13 +31,15 @@ export type CustomerInvoiceListDTO = {
companyId: UniqueID; companyId: UniqueID;
isProforma: boolean; isProforma: boolean;
invoiceNumber: CustomerInvoiceNumber; invoiceNumber: Maybe<CustomerInvoiceNumber>;
status: CustomerInvoiceStatus; status: CustomerInvoiceStatus;
series: Maybe<CustomerInvoiceSerie>; series: Maybe<CustomerInvoiceSerie>;
invoiceDate: UtcDate; invoiceDate: UtcDate;
operationDate: Maybe<UtcDate>; operationDate: Maybe<UtcDate>;
description: Maybe<string>;
customerId: UniqueID; customerId: UniqueID;
recipient: InvoiceRecipient; recipient: InvoiceRecipient;
@ -97,7 +99,9 @@ export class CustomerInvoiceListMapper
// 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) {
return Result.fail(new ValidationErrorCollection("Customer invoice mapping failed", errors)); return Result.fail(
new ValidationErrorCollection("Customer invoice mapping failed [mapToDTO]", errors)
);
} }
return Result.ok({ return Result.ok({
@ -110,6 +114,8 @@ export class CustomerInvoiceListMapper
invoiceDate: attributes.invoiceDate!, invoiceDate: attributes.invoiceDate!,
operationDate: attributes.operationDate!, operationDate: attributes.operationDate!,
description: attributes.description!,
customerId: attributes.customerId!, customerId: attributes.customerId!,
recipient: recipientResult.data, recipient: recipientResult.data,
@ -148,7 +154,7 @@ export class CustomerInvoiceListMapper
); );
const invoiceNumber = extractOrPushError( const invoiceNumber = extractOrPushError(
CustomerInvoiceNumber.create(raw.invoice_number), maybeFromNullableVO(raw.invoice_number, (value) => CustomerInvoiceNumber.create(value)),
"invoice_number", "invoice_number",
errors errors
); );
@ -165,6 +171,12 @@ export class CustomerInvoiceListMapper
errors errors
); );
const description = extractOrPushError(
maybeFromNullableVO(raw.description, (value) => value),
"description",
errors
);
const languageCode = extractOrPushError( const languageCode = extractOrPushError(
LanguageCode.create(raw.language_code), LanguageCode.create(raw.language_code),
"language_code", "language_code",
@ -241,6 +253,7 @@ export class CustomerInvoiceListMapper
invoiceNumber, invoiceNumber,
invoiceDate, invoiceDate,
operationDate, operationDate,
description,
languageCode, languageCode,
currencyCode, currencyCode,
discountPercentage, discountPercentage,

View File

@ -209,7 +209,9 @@ export class CustomerListMapper
// Si hubo errores de mapeo, devolvemos colección de validación // Si hubo errores de mapeo, devolvemos colección de validación
if (errors.length > 0) { if (errors.length > 0) {
return Result.fail(new ValidationErrorCollection("Customer invoice mapping failed", errors)); return Result.fail(
new ValidationErrorCollection("Customer mapping failed [mapToDTO]", errors)
);
} }
return Result.ok<CustomerListDTO>({ return Result.ok<CustomerListDTO>({