feat(subscriptions): implement subscription quota enforcement

- Apply QuotaGuard + @RequireQuota to listing creation and analytics endpoints
- Add QuotaExceeded domain event emitted when quota is exceeded
- Create ListingCreatedUsageHandler to auto-meter usage on listing creation
- Create QuotaExceededListener to send email notifications on quota exceeded
- Add maxAnalyticsQueries and maxMediaUploads fields to Plan model
- Add quota.exceeded email notification template
- Define quota limits per plan tier in seed data
- Add 15 unit tests covering guard, event handler, listener, and event

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 14:16:32 +07:00
parent 23bb380d34
commit 3864f78405
17 changed files with 474 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import { GetBillingHistoryHandler } from './application/queries/get-billing-hist
import { GetPlanHandler } from './application/queries/get-plan/get-plan.handler';
import { SUBSCRIPTION_REPOSITORY } from './domain/repositories/subscription.repository';
import { PrismaSubscriptionRepository } from './infrastructure/repositories/prisma-subscription.repository';
import { ListingCreatedUsageHandler } from './infrastructure/event-handlers/listing-created-usage.handler';
import { SubscriptionsController } from './presentation/controllers/subscriptions.controller';
import { QuotaGuard } from './presentation/guards/quota.guard';
@@ -35,6 +36,9 @@ const QueryHandlers = [
// Guards
QuotaGuard,
// Event Listeners
ListingCreatedUsageHandler,
// CQRS
...CommandHandlers,
...QueryHandlers,