79 lines
1.8 KiB
TypeScript
79 lines
1.8 KiB
TypeScript
import { AggregateRoot, UniqueID, UtcDate } from "@/core/common/domain";
|
|
import { Maybe, Result } from "@repo/rdx-utils";
|
|
import { Customer, CustomerInvoiceItem } from "../entities";
|
|
import { InvoiceStatus } from "../value-objetcs";
|
|
|
|
export interface ICustomerInvoiceProps {
|
|
status: InvoiceStatus;
|
|
issueDate: UtcDate;
|
|
invoiceNumber: string;
|
|
invoiceType: string;
|
|
invoiceCustomerReference: Maybe<string>;
|
|
|
|
customer: Customer;
|
|
items: CustomerInvoiceItem[];
|
|
}
|
|
|
|
export interface ICustomerInvoice {
|
|
id: UniqueID;
|
|
status: InvoiceStatus;
|
|
issueDate: UtcDate;
|
|
invoiceNumber: string;
|
|
invoiceType: string;
|
|
invoiceCustomerReference: Maybe<string>;
|
|
|
|
customer: Customer;
|
|
items: CustomerInvoiceItem[];
|
|
|
|
//send();
|
|
//accept();
|
|
}
|
|
|
|
export class CustomerInvoice
|
|
extends AggregateRoot<ICustomerInvoiceProps>
|
|
implements ICustomerInvoice
|
|
{
|
|
id: UniqueID;
|
|
static create(props: ICustomerInvoiceProps, id?: UniqueID): Result<CustomerInvoice, Error> {
|
|
const invoice = new CustomerInvoice(props, id);
|
|
|
|
// Reglas de negocio / validaciones
|
|
// ...
|
|
// ...
|
|
|
|
// 🔹 Disparar evento de dominio "CustomerAuthenticatedEvent"
|
|
//const { customer } = props;
|
|
//user.addDomainEvent(new CustomerAuthenticatedEvent(id, customer.toString()));
|
|
|
|
return Result.ok(invoice);
|
|
}
|
|
|
|
get status(): InvoiceStatus {
|
|
return this.props.status;
|
|
}
|
|
|
|
get issueDate(): UtcDate {
|
|
return this.props.issueDate;
|
|
}
|
|
|
|
get invoiceNumber(): string {
|
|
return this.props.invoiceNumber;
|
|
}
|
|
|
|
get invoiceType(): string {
|
|
return this.props.invoiceType;
|
|
}
|
|
|
|
get invoiceCustomerReference(): Maybe<string> {
|
|
return this.props.invoiceCustomerReference;
|
|
}
|
|
|
|
get customer(): Customer {
|
|
return this.props.customer;
|
|
}
|
|
|
|
get items(): CustomerInvoiceItem[] {
|
|
return this.props.items;
|
|
}
|
|
}
|