Skip to main content

Domain Entities

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.

Customer

Represents a customer in the system with contact information and metadata.

Interface

src/domain/entities/Customer.ts
export interface Customer {
  id?: string;
  email: string;
  phone: string;
  name: string;
  createdAt?: Date;
}
id
string
Unique identifier for the customer (auto-generated)
email
string
required
Customer’s email address
phone
string
required
Customer’s phone number
name
string
required
Customer’s full name
createdAt
Date
Timestamp when the customer was created (auto-generated)

Factory Function

function createCustomer(
  data: Omit<Customer, "id" | "createdAt">
): Customer
Creates a new customer with auto-generated timestamps.
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()

Order

Represents a subscription order for a streaming plan.

Interface

src/domain/entities/Order.ts
export interface Order {
  id?: string;
  customerId: string;
  planId: string;
  devices: number;
  months: number;
  amount: number;
  paymentMethod: PaymentMethod;
  paymentReceiptId: string;
  status: OrderStatus;
  activationDate: Date;
  expirationDate: Date;
  createdAt?: Date;
}
id
string
Unique identifier for the order (auto-generated)
customerId
string
required
Reference to the customer who placed the order
planId
string
required
Reference to the subscription plan
devices
number
required
Number of simultaneous devices allowed (1, 2, or 3)
months
number
required
Subscription duration in months (1, 2, 3, 6, or 12)
amount
number
required
Total payment amount
paymentMethod
PaymentMethod
required
Payment method used: "stripe" or "paypal"
paymentReceiptId
string
required
Payment gateway receipt/transaction ID
status
OrderStatus
required
Order status: "pending", "completed", or "failed"
activationDate
Date
required
When the subscription becomes active (auto-generated)
expirationDate
Date
required
When the subscription expires (auto-calculated based on months)
createdAt
Date
Timestamp when the order was created (auto-generated)

Type Definitions

export type PaymentMethod = "stripe" | "paypal";
Supported payment gateways for processing orders.

Factory Function

function createOrder(
  data: Omit<Order, "id" | "createdAt" | "activationDate" | "expirationDate">
): Order
Creates a new order with auto-generated dates and timestamps.
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()

Plan

Represents a subscription plan with pricing tiers and features.

Interface

src/domain/entities/Plan.ts
export interface Plan {
  id: string;
  devices: DeviceCount;
  name: string;
  description: string;
  prices: PlanPrice[];
  features: string[];
  popular?: boolean;
}
id
string
required
Unique identifier for the plan (e.g., "plan-1", "plan-2", "plan-3")
devices
DeviceCount
required
Number of simultaneous devices: 1, 2, or 3
name
string
required
Plan name: "Basic", "Standard", or "Premium"
description
string
required
Human-readable description of the plan
prices
PlanPrice[]
required
Array of pricing options for different durations
features
string[]
required
List of features included in this plan
Whether this plan should be highlighted as popular (true for Standard plan)

Type Definitions

export type DeviceCount = 1 | 2 | 3;
Number of simultaneous streaming devices allowed.

Factory Function

function createPlan(devices: DeviceCount): Plan
Creates a subscription plan with predefined pricing and features.
import { createPlan, PLANS } from '@/domain/entities/Plan';

// Create a single plan
const standardPlan = createPlan(2);

console.log(standardPlan);
// {
//   id: 'plan-2',
//   devices: 2,
//   name: 'Standard',
//   description: 'Disfruta Connect World en 2 dispositivos',
//   prices: [
//     { months: 1, price: 15, label: '1 mes' },
//     { months: 2, price: 25, label: '2 meses' },
//     // ... more pricing tiers
//   ],
//   features: [
//     '2 dispositivos simultáneos',
//     'HD & Full HD',
//     'Acceso ilimitado a catálogo',
//     'Perfiles personalizados',
//     'Soporte 24/7'
//   ],
//   popular: true
// }

// Use predefined plans
import { PLANS } from '@/domain/entities/Plan';
const [basic, standard, premium] = PLANS;

Predefined Plans

export const PLANS: Plan[] = [
  createPlan(1),  // Basic
  createPlan(2),  // Standard (popular)
  createPlan(3),  // Premium
];
A constant array containing all three subscription plans, ready to use.

Build docs developers (and LLMs) love