This commit is contained in:
David Arranz 2025-09-27 13:52:30 +02:00
parent bf960bc3ac
commit 3042255fad
5 changed files with 72 additions and 22 deletions

View File

@ -52,7 +52,44 @@ export type CustomerPatchProps = Partial<Omit<CustomerProps, "companyId" | "addr
address?: PostalAddressPatchProps;
};
export class Customer extends AggregateRoot<CustomerProps> {
// Customer
export interface ICustomer {
// comportamiento
update(partialCustomer: CustomerPatchProps): Result<Customer, Error>;
// propiedades (getters)
readonly isIndividual: boolean;
readonly isCompany: boolean;
readonly isActive: boolean;
readonly companyId: UniqueID;
readonly reference: Maybe<Name>;
readonly name: Name;
readonly tradeName: Maybe<Name>;
readonly tin: Maybe<TINNumber>;
readonly address: PostalAddress;
readonly emailPrimary: Maybe<EmailAddress>;
readonly emailSecondary: Maybe<EmailAddress>;
readonly phonePrimary: Maybe<PhoneNumber>;
readonly phoneSecondary: Maybe<PhoneNumber>;
readonly mobilePrimary: Maybe<PhoneNumber>;
readonly mobileSecondary: Maybe<PhoneNumber>;
readonly fax: Maybe<PhoneNumber>;
readonly website: Maybe<URLAddress>;
readonly legalRecord: Maybe<TextValue>;
readonly defaultTaxes: Collection<TaxCode>;
readonly languageCode: LanguageCode;
readonly currencyCode: CurrencyCode;
}
export class Customer extends AggregateRoot<CustomerProps> implements ICustomer {
static create(props: CustomerProps, id?: UniqueID): Result<Customer, Error> {
const contact = new Customer(props, id);
@ -60,9 +97,9 @@ export class Customer extends AggregateRoot<CustomerProps> {
// ...
// ...
// 🔹 Disparar evento de dominio "CustomerAuthenticatedEvent"
//const { contact } = props;
//user.addDomainEvent(new CustomerAuthenticatedEvent(id, contact.toString()));
// Disparar eventos de dominio
// ...
// ...
return Result.ok(contact);
}

View File

@ -39,12 +39,12 @@ export type CustomerListDTO = {
address: PostalAddress;
email_primary: Maybe<EmailAddress>;
email_secondary: Maybe<EmailAddress>;
phone_primary: Maybe<PhoneNumber>;
phone_secondary: Maybe<PhoneNumber>;
mobile_primary: Maybe<PhoneNumber>;
mobile_secondary: Maybe<PhoneNumber>;
emailPrimary: Maybe<EmailAddress>;
emailSecondary: Maybe<EmailAddress>;
phonePrimary: Maybe<PhoneNumber>;
phoneSecondary: Maybe<PhoneNumber>;
mobilePrimary: Maybe<PhoneNumber>;
mobileSecondary: Maybe<PhoneNumber>;
fax: Maybe<PhoneNumber>;
website: Maybe<URLAddress>;
@ -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!,

View File

@ -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(),

View File

@ -10,7 +10,7 @@ export abstract class AggregateRoot<T extends object> extends DomainEntity<T> {
}
/**
* 🔹 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<T extends object> extends DomainEntity<T> {
}
/**
* 🔹 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);

View File

@ -9,7 +9,16 @@
* console.log(noValue.isSome()); // false
**/
export class Maybe<T> {
export interface IMaybe<T> {
isSome(): boolean;
isNone(): boolean;
unwrap(): T | undefined;
getOrUndefined(): T | undefined;
map<U>(fn: (value: T) => U): IMaybe<U>;
match<U>(someFn: (value: T) => U, noneFn: () => U): U;
}
export class Maybe<T> implements IMaybe<T> {
private constructor(private readonly value?: T) {}
static fromNullable<T>(value?: T): Maybe<T> {