Entities are the core business objects in the domain layer. Each entity has a unique identity and represents a key concept in the Connect World streaming service.
function createCustomer( data: Omit<Customer, "id" | "createdAt">): Customer
Creates a new customer with auto-generated timestamps.
Example Usage
import { createCustomer } from '@/domain/entities/Customer';import { Email } from '@/domain/value-objects/Email';import { Phone } from '@/domain/value-objects/Phone';const email = new Email('[email protected]');const phone = new Phone('+1234567890');const customer = createCustomer({ name: 'John Doe', email: email.toString(), phone: phone.toString(),});// customer.createdAt is automatically set to new Date()
function createOrder( data: Omit<Order, "id" | "createdAt" | "activationDate" | "expirationDate">): Order
Creates a new order with auto-generated dates and timestamps.
Show Implementation Details
The factory function automatically:
Sets activationDate to the current date
Calculates expirationDate by adding the specified months to the activation date
Sets createdAt to the current timestamp
src/domain/entities/Order.ts
export function createOrder(data: Omit<Order, "id" | "createdAt" | "activationDate" | "expirationDate">): Order { const activationDate = new Date(); const expirationDate = new Date(); expirationDate.setMonth(expirationDate.getMonth() + data.months); return { ...data, activationDate, expirationDate, createdAt: new Date(), };}
Example Usage
import { createOrder } from '@/domain/entities/Order';const order = createOrder({ customerId: 'cust_123', planId: 'plan-2', devices: 2, months: 6, amount: 70, paymentMethod: 'stripe', paymentReceiptId: 'pi_abc123', status: 'completed',});// order.activationDate is set to now// order.expirationDate is set to 6 months from now// order.createdAt is set to new Date()