import { Module } from '@nestjs/common'; import { APP_INTERCEPTOR } from '@nestjs/core'; import { ConfigModule } from '@nestjs/config'; import { ServeStaticModule } from '@nestjs/serve-static'; import { ScheduleModule } from '@nestjs/schedule'; import { join } from 'path'; import { configurations } from './config'; import { PrismaService } from './infrastructure/persistence/prisma/prisma.service'; import { AppVersionMapper } from './infrastructure/persistence/mappers/app-version.mapper'; import { AppVersionRepositoryImpl } from './infrastructure/persistence/repositories/app-version.repository.impl'; import { APP_VERSION_REPOSITORY } from './domain/repositories/app-version.repository'; import { FileStorageService } from './infrastructure/storage/file-storage.service'; import { PackageParserService } from './infrastructure/parsers/package-parser.service'; import { CheckUpdateHandler } from './application/queries/check-update/check-update.handler'; import { ListVersionsHandler } from './application/queries/list-versions/list-versions.handler'; import { GetVersionHandler } from './application/queries/get-version/get-version.handler'; import { CreateVersionHandler } from './application/commands/create-version/create-version.handler'; import { UpdateVersionHandler } from './application/commands/update-version/update-version.handler'; import { DeleteVersionHandler } from './application/commands/delete-version/delete-version.handler'; import { ToggleVersionHandler } from './application/commands/toggle-version/toggle-version.handler'; import { UploadVersionHandler } from './application/commands/upload-version/upload-version.handler'; import { VersionController } from './api/controllers/version.controller'; import { MobileVersionController } from './api/controllers/mobile-version.controller'; import { HealthController } from './api/controllers/health.controller'; import { DownloadController } from './api/controllers/download.controller'; // Notification imports import { NotificationMapper } from './infrastructure/persistence/mappers/notification.mapper'; import { NotificationRepositoryImpl } from './infrastructure/persistence/repositories/notification.repository.impl'; import { NOTIFICATION_REPOSITORY } from './domain/repositories/notification.repository'; import { AdminNotificationController, MobileNotificationController } from './api/controllers/notification.controller'; // User Management imports import { UserQueryRepositoryImpl } from './infrastructure/persistence/repositories/user-query.repository.impl'; import { USER_QUERY_REPOSITORY } from './domain/repositories/user-query.repository'; import { UserController } from './api/controllers/user.controller'; import { UserDetailController } from './api/controllers/user-detail.controller'; import { UserEventConsumerService } from './infrastructure/kafka/user-event-consumer.service'; // CDC Consumer imports import { CdcConsumerService } from './infrastructure/kafka/cdc-consumer.service'; import { ReferralCdcConsumerService } from './infrastructure/kafka/referral-cdc-consumer.service'; import { WalletCdcConsumerService } from './infrastructure/kafka/wallet-cdc-consumer.service'; import { PlantingCdcConsumerService } from './infrastructure/kafka/planting-cdc-consumer.service'; import { AuthorizationCdcConsumerService } from './infrastructure/kafka/authorization-cdc-consumer.service'; // User Detail Query imports import { UserDetailQueryRepositoryImpl } from './infrastructure/persistence/repositories/user-detail-query.repository.impl'; import { USER_DETAIL_QUERY_REPOSITORY } from './domain/repositories/user-detail-query.repository'; // System Config imports import { SystemConfigRepositoryImpl } from './infrastructure/persistence/repositories/system-config.repository.impl'; import { SYSTEM_CONFIG_REPOSITORY } from './domain/repositories/system-config.repository'; import { AdminSystemConfigController, PublicSystemConfigController } from './api/controllers/system-config.controller'; // User Profile System imports (标签、规则、人群包) import { USER_TAG_REPOSITORY } from './domain/repositories/user-tag.repository'; import { UserTagRepositoryImpl } from './infrastructure/persistence/repositories/user-tag.repository.impl'; import { CLASSIFICATION_RULE_REPOSITORY } from './domain/repositories/classification-rule.repository'; import { ClassificationRuleRepositoryImpl } from './infrastructure/persistence/repositories/classification-rule.repository.impl'; import { AUDIENCE_SEGMENT_REPOSITORY } from './domain/repositories/audience-segment.repository'; import { AudienceSegmentRepositoryImpl } from './infrastructure/persistence/repositories/audience-segment.repository.impl'; import { RuleEngineService } from './application/services/rule-engine.service'; import { UserTaggingService } from './application/services/user-tagging.service'; import { AudienceSegmentService } from './application/services/audience-segment.service'; import { UserTagController } from './api/controllers/user-tag.controller'; import { ClassificationRuleController } from './api/controllers/classification-rule.controller'; import { AudienceSegmentController } from './api/controllers/audience-segment.controller'; import { AutoTagSyncJob } from './infrastructure/jobs/auto-tag-sync.job'; // Co-Managed Wallet imports import { CoManagedWalletController } from './api/controllers/co-managed-wallet.controller'; import { CoManagedWalletService } from './application/services/co-managed-wallet.service'; import { CoManagedWalletMapper } from './infrastructure/persistence/mappers/co-managed-wallet.mapper'; import { CoManagedWalletSessionRepositoryImpl } from './infrastructure/persistence/repositories/co-managed-wallet-session.repository.impl'; import { CoManagedWalletRepositoryImpl } from './infrastructure/persistence/repositories/co-managed-wallet.repository.impl'; import { CO_MANAGED_WALLET_SESSION_REPOSITORY, CO_MANAGED_WALLET_REPOSITORY, } from './domain/repositories/co-managed-wallet.repository'; // System Maintenance imports import { SYSTEM_MAINTENANCE_REPOSITORY } from './domain/repositories/system-maintenance.repository'; import { SystemMaintenanceRepositoryImpl } from './infrastructure/persistence/repositories/system-maintenance.repository.impl'; import { AdminMaintenanceController, MobileMaintenanceController } from './api/controllers/system-maintenance.controller'; import { MaintenanceInterceptor } from './api/interceptors/maintenance.interceptor'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, load: configurations, }), // Serve static files from uploads directory ServeStaticModule.forRoot({ rootPath: join(process.cwd(), process.env.UPLOAD_DIR || 'uploads'), serveRoot: '/uploads', }), // Schedule module for cron jobs ScheduleModule.forRoot(), ], controllers: [ VersionController, MobileVersionController, HealthController, DownloadController, AdminNotificationController, MobileNotificationController, UserController, UserDetailController, AdminSystemConfigController, PublicSystemConfigController, // User Profile System Controllers UserTagController, ClassificationRuleController, AudienceSegmentController, // Co-Managed Wallet Controller CoManagedWalletController, // System Maintenance Controllers AdminMaintenanceController, MobileMaintenanceController, ], providers: [ PrismaService, AppVersionMapper, FileStorageService, PackageParserService, { provide: APP_VERSION_REPOSITORY, useClass: AppVersionRepositoryImpl, }, // Query Handlers CheckUpdateHandler, ListVersionsHandler, GetVersionHandler, // Command Handlers CreateVersionHandler, UpdateVersionHandler, DeleteVersionHandler, ToggleVersionHandler, UploadVersionHandler, // Notification NotificationMapper, { provide: NOTIFICATION_REPOSITORY, useClass: NotificationRepositoryImpl, }, // User Management { provide: USER_QUERY_REPOSITORY, useClass: UserQueryRepositoryImpl, }, { provide: USER_DETAIL_QUERY_REPOSITORY, useClass: UserDetailQueryRepositoryImpl, }, UserEventConsumerService, // CDC Consumers (Debezium) CdcConsumerService, ReferralCdcConsumerService, WalletCdcConsumerService, PlantingCdcConsumerService, AuthorizationCdcConsumerService, // System Config { provide: SYSTEM_CONFIG_REPOSITORY, useClass: SystemConfigRepositoryImpl, }, // User Profile System (标签、规则、人群包) { provide: USER_TAG_REPOSITORY, useClass: UserTagRepositoryImpl, }, { provide: CLASSIFICATION_RULE_REPOSITORY, useClass: ClassificationRuleRepositoryImpl, }, { provide: AUDIENCE_SEGMENT_REPOSITORY, useClass: AudienceSegmentRepositoryImpl, }, RuleEngineService, UserTaggingService, AudienceSegmentService, // Scheduled Jobs AutoTagSyncJob, // Co-Managed Wallet CoManagedWalletMapper, CoManagedWalletService, { provide: CO_MANAGED_WALLET_SESSION_REPOSITORY, useClass: CoManagedWalletSessionRepositoryImpl, }, { provide: CO_MANAGED_WALLET_REPOSITORY, useClass: CoManagedWalletRepositoryImpl, }, // System Maintenance { provide: SYSTEM_MAINTENANCE_REPOSITORY, useClass: SystemMaintenanceRepositoryImpl, }, // Global Interceptors { provide: APP_INTERCEPTOR, useClass: MaintenanceInterceptor, }, ], }) export class AppModule {}