diff --git a/modules/customer-invoices/src/api/application/issued-invoices/snapshot-builders/full/issued-invoice-recipient-full-snapshot-builder.ts b/modules/customer-invoices/src/api/application/issued-invoices/snapshot-builders/full/issued-invoice-recipient-full-snapshot-builder.ts index 3f2ec0e1..a8fa8332 100644 --- a/modules/customer-invoices/src/api/application/issued-invoices/snapshot-builders/full/issued-invoice-recipient-full-snapshot-builder.ts +++ b/modules/customer-invoices/src/api/application/issued-invoices/snapshot-builders/full/issued-invoice-recipient-full-snapshot-builder.ts @@ -1,5 +1,5 @@ import type { ISnapshotBuilder } from "@erp/core/api"; -import { DomainValidationError, maybeToNullable } from "@repo/rdx-ddd"; +import { DomainValidationError, maybeToEmptyString, maybeToNullable } from "@repo/rdx-ddd"; import type { IssuedInvoice } from "../../../../domain"; @@ -22,7 +22,7 @@ export class IssuedInvoiceRecipientFullSnapshotBuilder return { id: invoice.customerId.toString(), name: recipient.name.toString(), - tin: recipient.tin.toString(), + tin: maybeToEmptyString(recipient.tin, (v) => v.toString()), street: maybeToNullable(recipient.street, (v) => v.toString()), street2: maybeToNullable(recipient.street2, (v) => v.toString()), city: maybeToNullable(recipient.city, (v) => v.toString()), diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-recipient-full-snapshot-builder.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-recipient-full-snapshot-builder.ts index 07cd295d..0cefef45 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-recipient-full-snapshot-builder.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-recipient-full-snapshot-builder.ts @@ -19,7 +19,7 @@ export class ProformaRecipientFullSnapshotBuilder implements IProformaRecipientF (recipient: InvoiceRecipient) => ({ id: proforma.customerId.toString(), name: recipient.name.toString(), - tin: recipient.tin.toString(), + tin: maybeToNullable(recipient.tin, (v) => v.toString()), street: maybeToNullable(recipient.street, (v) => v.toString()), street2: maybeToNullable(recipient.street2, (v) => v.toString()), city: maybeToNullable(recipient.city, (v) => v.toString()), diff --git a/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/invoice-recipient.vo.ts b/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/invoice-recipient.vo.ts index 3097cb0d..e41054d0 100644 --- a/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/invoice-recipient.vo.ts +++ b/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/invoice-recipient.vo.ts @@ -13,7 +13,7 @@ import { type Maybe, Result } from "@repo/rdx-utils"; export type InvoiceRecipientProps = { name: Name; - tin: TINNumber; + tin: Maybe; street: Maybe; street2: Maybe; city: Maybe; @@ -50,7 +50,7 @@ export class InvoiceRecipient extends ValueObject { return this.props.name; } - public get tin(): TINNumber { + public get tin(): Maybe { return this.props.tin; } @@ -88,7 +88,7 @@ export class InvoiceRecipient extends ValueObject { toObjectString() { return { - tin: this.tin.toString(), + tin: maybeToNullable(this.tin, (value) => value.toString()), name: this.name.toString(), street: maybeToNullable(this.street, (value) => value.toString()), street2: maybeToNullable(this.street2, (value) => value.toString()), diff --git a/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts b/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts index 6d216c54..9b461410 100644 --- a/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts @@ -44,7 +44,12 @@ export class SequelizeIssuedInvoiceRecipientDomainMapper { // Customer (snapshot) const customerName = extractOrPushError(Name.create(_name!), "customer_name", errors); - const customerTin = extractOrPushError(TINNumber.create(_tin!), "customer_tin", errors); + //const customerTin = extractOrPushError(TINNumber.create(_tin!), "customer_tin", errors); + const customerTin = extractOrPushError( + maybeFromNullableResult(_tin, (value) => TINNumber.create(value)), + "customer_tin", + errors + ); const customerStreet = extractOrPushError( maybeFromNullableResult(_street, (value) => Street.create(value)), @@ -122,7 +127,7 @@ export class SequelizeIssuedInvoiceRecipientDomainMapper { const recipient = source; return { - customer_tin: recipient.tin.toPrimitive(), + customer_tin: maybeToNullable(recipient.tin, (value) => value.toString()), customer_name: recipient.name.toPrimitive(), customer_street: maybeToNullable(recipient.street, (v) => v.toPrimitive()), customer_street2: maybeToNullable(recipient.street2, (v) => v.toPrimitive()), diff --git a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-domain.mapper.ts b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-domain.mapper.ts index 85614c58..dbba490b 100644 --- a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-domain.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-domain.mapper.ts @@ -229,6 +229,7 @@ export class SequelizeProformaDomainMapper extends SequelizeDomainMapper< // 4) Si hubo errores de mapeo, devolvemos colección de validación if (errors.length > 0) { + console.error(errors); return Result.fail( new ValidationErrorCollection("Customer invoice mapping failed [mapToDomain]", errors) ); diff --git a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts index a71da7e6..e7f68d9f 100644 --- a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts @@ -43,7 +43,11 @@ export class SequelizeProformaRecipientDomainMapper { // Customer (snapshot) const customerName = extractOrPushError(Name.create(_name!), "customer_name", errors); - const customerTin = extractOrPushError(TINNumber.create(_tin!), "customer_tin", errors); + const customerTin = extractOrPushError( + maybeFromNullableResult(_tin, (value) => TINNumber.create(value)), + "customer_tin", + errors + ); const customerStreet = extractOrPushError( maybeFromNullableResult(_street, (value) => Street.create(value)), diff --git a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts index 305e721e..5568ea18 100644 --- a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts @@ -43,19 +43,24 @@ export class SequelizeInvoiceRecipientSummaryMapper extends SequelizeQueryMapper message: "Current customer not included in query (SequelizeInvoiceRecipientListMapper)", }); } - const _name = raw.current_customer.name; - const _tin = raw.current_customer.tin; - const _street = raw.current_customer.street; - const _street2 = raw.current_customer.street2; - const _city = raw.current_customer.city; - const _postal_code = raw.current_customer.postal_code; - const _province = raw.current_customer.province; - const _country = raw.current_customer.country; + const _name = raw.current_customer!.name; + const _tin = raw.current_customer!.tin; + const _street = raw.current_customer!.street; + const _street2 = raw.current_customer!.street2; + const _city = raw.current_customer!.city; + const _postal_code = raw.current_customer!.postal_code; + const _province = raw.current_customer!.province; + const _country = raw.current_customer!.country; // Customer (snapshot) const customerName = extractOrPushError(Name.create(_name!), "customer_name", errors); - const customerTin = extractOrPushError(TINNumber.create(_tin!), "customer_tin", errors); + //const customerTin = extractOrPushError(TINNumber.create(_tin!), "customer_tin", errors); + const customerTin = extractOrPushError( + maybeFromNullableResult(_tin, (value) => TINNumber.create(value)), + "customer_tin", + errors + ); const customerStreet = extractOrPushError( maybeFromNullableResult(_street, (value) => Street.create(value)), diff --git a/modules/customers/src/api/application/mappers/create-customer-input.mapper.ts b/modules/customers/src/api/application/mappers/create-customer-input.mapper.ts index a208e0d0..b702bf1a 100644 --- a/modules/customers/src/api/application/mappers/create-customer-input.mapper.ts +++ b/modules/customers/src/api/application/mappers/create-customer-input.mapper.ts @@ -12,7 +12,6 @@ import { Province, Street, TINNumber, - type TaxCode, TextValue, URLAddress, UniqueID, @@ -68,85 +67,89 @@ export class CreateCustomerInputMapper implements ICreateCustomerInputMapper { ); const street = extractOrPushError( - maybeFromNullableResult(dto.street, (value) => Street.create(value)), + maybeFromNullableResult(dto.address.street, (value) => Street.create(value)), "street", errors ); const street2 = extractOrPushError( - maybeFromNullableResult(dto.street2, (value) => Street.create(value)), + maybeFromNullableResult(dto.address.street2, (value) => Street.create(value)), "street2", errors ); const city = extractOrPushError( - maybeFromNullableResult(dto.city, (value) => City.create(value)), + maybeFromNullableResult(dto.address.city, (value) => City.create(value)), "city", errors ); const province = extractOrPushError( - maybeFromNullableResult(dto.province, (value) => Province.create(value)), + maybeFromNullableResult(dto.address.province, (value) => Province.create(value)), "province", errors ); const postalCode = extractOrPushError( - maybeFromNullableResult(dto.postal_code, (value) => PostalCode.create(value)), + maybeFromNullableResult(dto.address.postal_code, (value) => PostalCode.create(value)), "postal_code", errors ); const country = extractOrPushError( - maybeFromNullableResult(dto.country, (value) => Country.create(value)), + maybeFromNullableResult(dto.address.country, (value) => Country.create(value)), "country", errors ); const primaryEmailAddress = extractOrPushError( - maybeFromNullableResult(dto.email_primary, (value) => EmailAddress.create(value)), + maybeFromNullableResult(dto.contact?.email_primary, (value) => EmailAddress.create(value)), "email_primary", errors ); const secondaryEmailAddress = extractOrPushError( - maybeFromNullableResult(dto.email_secondary, (value) => EmailAddress.create(value)), + maybeFromNullableResult(dto.contact?.email_secondary, (value) => + EmailAddress.create(value) + ), "email_secondary", errors ); const primaryPhoneNumber = extractOrPushError( - maybeFromNullableResult(dto.phone_primary, (value) => PhoneNumber.create(value)), + maybeFromNullableResult(dto.contact?.phone_primary, (value) => PhoneNumber.create(value)), "phone_primary", errors ); const secondaryPhoneNumber = extractOrPushError( - maybeFromNullableResult(dto.phone_secondary, (value) => PhoneNumber.create(value)), + maybeFromNullableResult(dto.contact?.phone_secondary, (value) => PhoneNumber.create(value)), "phone_secondary", errors ); const primaryMobileNumber = extractOrPushError( - maybeFromNullableResult(dto.mobile_primary, (value) => PhoneNumber.create(value)), + maybeFromNullableResult(dto.contact?.mobile_primary, (value) => PhoneNumber.create(value)), "mobile_primary", errors ); const secondaryMobileNumber = extractOrPushError( - maybeFromNullableResult(dto.mobile_secondary, (value) => PhoneNumber.create(value)), + maybeFromNullableResult(dto.contact?.mobile_secondary, (value) => + PhoneNumber.create(value) + ), "mobile_secondary", errors ); const faxNumber = extractOrPushError( - maybeFromNullableResult(dto.fax, (value) => PhoneNumber.create(value)), + maybeFromNullableResult(dto.contact?.fax, (value) => PhoneNumber.create(value)), "fax", errors ); const website = extractOrPushError( - maybeFromNullableResult(dto.website, (value) => URLAddress.create(value)), + maybeFromNullableResult(dto.contact?.website, (value) => URLAddress.create(value)), "website", errors ); @@ -190,8 +193,6 @@ export class CreateCustomerInputMapper implements ICreateCustomerInputMapper { errors ); - const defaultTaxes: TaxCode[] = []; - if (errors.length > 0) { return Result.fail(new ValidationErrorCollection("Customer props mapping failed", errors)); } diff --git a/modules/customers/src/web/create/controllers/use-customer-create-page.controller.ts b/modules/customers/src/web/create/controllers/use-customer-create-page.controller.ts index 13c587db..23c03035 100644 --- a/modules/customers/src/web/create/controllers/use-customer-create-page.controller.ts +++ b/modules/customers/src/web/create/controllers/use-customer-create-page.controller.ts @@ -6,14 +6,16 @@ export const useCustomerCreatePageController = () => { const [searchParams] = useSearchParams(); const navigate = useNavigate(); + const returnTo = searchParams.get("returnTo") ?? "/customers"; + const createCtrl = useCustomerCreateController({ onCreated: (createdCustomer) => { - navigate(`/customers/${createdCustomer.id}/edit`); + navigate( + `/customers/${createdCustomer.id}/edit${returnTo ? `?returnTo=${encodeURIComponent(returnTo)}` : ""}` + ); }, }); - const returnTo = searchParams.get("returnTo") ?? "/customers"; - return { createCtrl, returnTo,