feat(subscriptions): add Subscriptions module with plans, quotas, and billing

- Add Subscription, Plan, UsageRecord domain entities
- Implement Create, Upgrade, Cancel subscription commands
- Add MeterUsage command for quota tracking
- Support 4 plan tiers: Free, Agent Pro, Investor, Enterprise
- Register SubscriptionsModule in AppModule

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 02:04:20 +07:00
parent f3081d92fc
commit 9b581b7e5f
32 changed files with 1205 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import { type DomainEvent } from '@modules/shared/domain/domain-event';
import { type PlanTier } from '@prisma/client';
export class SubscriptionCancelledEvent implements DomainEvent {
readonly eventName = 'subscription.cancelled';
readonly occurredAt = new Date();
constructor(
public readonly aggregateId: string,
public readonly userId: string,
public readonly planTier: PlanTier,
) {}
}

View File

@@ -0,0 +1,13 @@
import { type DomainEvent } from '@modules/shared/domain/domain-event';
import { type PlanTier } from '@prisma/client';
export class SubscriptionCreatedEvent implements DomainEvent {
readonly eventName = 'subscription.created';
readonly occurredAt = new Date();
constructor(
public readonly aggregateId: string,
public readonly userId: string,
public readonly planTier: PlanTier,
) {}
}

View File

@@ -0,0 +1,14 @@
import { type DomainEvent } from '@modules/shared/domain/domain-event';
import { type PlanTier } from '@prisma/client';
export class SubscriptionUpgradedEvent implements DomainEvent {
readonly eventName = 'subscription.upgraded';
readonly occurredAt = new Date();
constructor(
public readonly aggregateId: string,
public readonly userId: string,
public readonly fromTier: PlanTier,
public readonly toTier: PlanTier,
) {}
}