Uecko_ERP/apps/server/src/contexts/accounts/domain/aggregates/account.ts

131 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-02-20 18:55:24 +00:00
import {
AggregateRoot,
EmailAddress,
PhoneNumber,
PostalAddress,
TINNumber,
UniqueID,
} from "@common/domain";
import { Maybe, Result } from "@common/helpers";
2025-02-25 17:47:42 +00:00
export interface IAccountProps {
2025-02-20 18:55:24 +00:00
isFreelancer: boolean;
name: string;
tin: TINNumber;
address: PostalAddress;
email: EmailAddress;
phone: PhoneNumber;
legalRecord: string;
defaultTax: number;
status: string;
langCode: string;
currencyCode: string;
tradeName: Maybe<string>;
website: Maybe<string>;
fax: Maybe<PhoneNumber>;
logo: Maybe<string>;
}
2025-02-25 17:47:42 +00:00
export interface IAccount {
2025-02-20 18:55:24 +00:00
id: UniqueID;
name: string;
tin: TINNumber;
address: PostalAddress;
email: EmailAddress;
phone: PhoneNumber;
legalRecord: string;
defaultTax: number;
langCode: string;
currencyCode: string;
tradeName: Maybe<string>;
fax: Maybe<PhoneNumber>;
website: Maybe<string>;
logo: Maybe<string>;
2025-02-25 17:47:42 +00:00
isAccount: boolean;
2025-02-20 18:55:24 +00:00
isFreelancer: boolean;
isActive: boolean;
}
2025-02-25 17:47:42 +00:00
export class Account extends AggregateRoot<IAccountProps> implements IAccount {
static create(props: IAccountProps, id?: UniqueID): Result<Account, Error> {
const account = new Account(props, id);
2025-02-20 18:55:24 +00:00
// Reglas de negocio / validaciones
// ...
// ...
2025-02-25 17:47:42 +00:00
// 🔹 Disparar evento de dominio "AccountAuthenticatedEvent"
//const { account } = props;
//user.addDomainEvent(new AccountAuthenticatedEvent(id, account.toString()));
2025-02-20 18:55:24 +00:00
2025-02-25 17:47:42 +00:00
return Result.ok(account);
2025-02-20 18:55:24 +00:00
}
get name() {
return this.props.name;
}
get tradeName() {
return this.props.tradeName;
}
get tin(): TINNumber {
return this.props.tin;
}
get address(): PostalAddress {
return this.props.address;
}
get email(): EmailAddress {
return this.props.email;
}
get phone(): PhoneNumber {
return this.props.phone;
}
get fax(): Maybe<PhoneNumber> {
return this.props.fax;
}
get website() {
return this.props.website;
}
get legalRecord() {
return this.props.legalRecord;
}
get defaultTax() {
return this.props.defaultTax;
}
get langCode() {
return this.props.langCode;
}
get currencyCode() {
return this.props.currencyCode;
}
get logo() {
return this.props.logo;
}
2025-02-25 17:47:42 +00:00
get isAccount(): boolean {
2025-02-20 18:55:24 +00:00
return !this.props.isFreelancer;
}
get isFreelancer(): boolean {
return this.props.isFreelancer;
}
get isActive(): boolean {
return this.props.status === "active";
}
}