diff --git a/modules/customers/src/api/domain/aggregates/customer.ts b/modules/customers/src/api/domain/aggregates/customer.ts index ea304a99..efef5503 100644 --- a/modules/customers/src/api/domain/aggregates/customer.ts +++ b/modules/customers/src/api/domain/aggregates/customer.ts @@ -52,7 +52,44 @@ export type CustomerPatchProps = Partial { +// Customer +export interface ICustomer { + // comportamiento + update(partialCustomer: CustomerPatchProps): Result; + + // propiedades (getters) + readonly isIndividual: boolean; + readonly isCompany: boolean; + readonly isActive: boolean; + + readonly companyId: UniqueID; + + readonly reference: Maybe; + readonly name: Name; + readonly tradeName: Maybe; + readonly tin: Maybe; + + readonly address: PostalAddress; + + readonly emailPrimary: Maybe; + readonly emailSecondary: Maybe; + + readonly phonePrimary: Maybe; + readonly phoneSecondary: Maybe; + readonly mobilePrimary: Maybe; + readonly mobileSecondary: Maybe; + readonly fax: Maybe; + + readonly website: Maybe; + readonly legalRecord: Maybe; + + readonly defaultTaxes: Collection; + + readonly languageCode: LanguageCode; + readonly currencyCode: CurrencyCode; +} + +export class Customer extends AggregateRoot implements ICustomer { static create(props: CustomerProps, id?: UniqueID): Result { const contact = new Customer(props, id); @@ -60,9 +97,9 @@ export class Customer extends AggregateRoot { // ... // ... - // 🔹 Disparar evento de dominio "CustomerAuthenticatedEvent" - //const { contact } = props; - //user.addDomainEvent(new CustomerAuthenticatedEvent(id, contact.toString())); + // Disparar eventos de dominio + // ... + // ... return Result.ok(contact); } diff --git a/modules/customers/src/api/infrastructure/mappers/queries/customer.list.mapper.ts b/modules/customers/src/api/infrastructure/mappers/queries/customer.list.mapper.ts index de48b466..59ece247 100644 --- a/modules/customers/src/api/infrastructure/mappers/queries/customer.list.mapper.ts +++ b/modules/customers/src/api/infrastructure/mappers/queries/customer.list.mapper.ts @@ -39,12 +39,12 @@ export type CustomerListDTO = { address: PostalAddress; - email_primary: Maybe; - email_secondary: Maybe; - phone_primary: Maybe; - phone_secondary: Maybe; - mobile_primary: Maybe; - mobile_secondary: Maybe; + emailPrimary: Maybe; + emailSecondary: Maybe; + phonePrimary: Maybe; + phoneSecondary: Maybe; + mobilePrimary: Maybe; + mobileSecondary: Maybe; fax: Maybe; website: Maybe; @@ -225,12 +225,12 @@ export class CustomerListMapper address: postalAddress!, - email_primary: emailPrimaryAddress!, - email_secondary: emailSecondaryAddress!, - phone_primary: phonePrimaryNumber!, - phone_secondary: phoneSecondaryNumber!, - mobile_primary: mobilePrimaryNumber!, - mobile_secondary: mobileSecondaryNumber!, + emailPrimary: emailPrimaryAddress!, + emailSecondary: emailSecondaryAddress!, + phonePrimary: phonePrimaryNumber!, + phoneSecondary: phoneSecondaryNumber!, + mobilePrimary: mobilePrimaryNumber!, + mobileSecondary: mobileSecondaryNumber!, fax: faxNumber!, website: website!, diff --git a/modules/customers/src/common/dto/response/list-customers.response.dto.ts b/modules/customers/src/common/dto/response/list-customers.response.dto.ts index 060594c6..c890082c 100644 --- a/modules/customers/src/common/dto/response/list-customers.response.dto.ts +++ b/modules/customers/src/common/dto/response/list-customers.response.dto.ts @@ -19,8 +19,12 @@ export const ListCustomersResponseSchema = createListViewResponseSchema( postal_code: z.string(), country: z.string(), - email: z.string(), - phone: z.string(), + email_primary: z.string(), + email_secondary: z.string(), + phone_primary: z.string(), + phone_secondary: z.string(), + mobile_primary: z.string(), + mobile_secondary: z.string(), fax: z.string(), website: z.string(), diff --git a/packages/rdx-ddd/src/aggregate-root.ts b/packages/rdx-ddd/src/aggregate-root.ts index 32ffde8a..bfc84cfe 100644 --- a/packages/rdx-ddd/src/aggregate-root.ts +++ b/packages/rdx-ddd/src/aggregate-root.ts @@ -10,7 +10,7 @@ export abstract class AggregateRoot extends DomainEntity { } /** - * 🔹 Agregar un evento de dominio al agregado + * Agregar un evento de dominio al agregado */ protected addDomainEvent(event: IDomainEvent): void { this._domainEvents.push(event); @@ -20,14 +20,14 @@ export abstract class AggregateRoot extends DomainEntity { } /** - * 🔹 Obtener los eventos de dominio pendientes + * Obtener los eventos de dominio pendientes */ get domainEvents(): IDomainEvent[] { return this._domainEvents; } /** - * 🔹 Limpiar la lista de eventos después de procesarlos + * Limpiar la lista de eventos después de procesarlos */ public clearDomainEvents(): void { this._domainEvents.splice(0, this._domainEvents.length); diff --git a/packages/rdx-utils/src/helpers/maybe.ts b/packages/rdx-utils/src/helpers/maybe.ts index 03560cab..b2187c74 100644 --- a/packages/rdx-utils/src/helpers/maybe.ts +++ b/packages/rdx-utils/src/helpers/maybe.ts @@ -9,7 +9,16 @@ * console.log(noValue.isSome()); // false **/ -export class Maybe { +export interface IMaybe { + isSome(): boolean; + isNone(): boolean; + unwrap(): T | undefined; + getOrUndefined(): T | undefined; + map(fn: (value: T) => U): IMaybe; + match(someFn: (value: T) => U, noneFn: () => U): U; +} + +export class Maybe implements IMaybe { private constructor(private readonly value?: T) {} static fromNullable(value?: T): Maybe {