93 lines
3.0 KiB
TypeScript
93 lines
3.0 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { CqrsModule } from '@nestjs/cqrs';
|
|
import { JwtModule } from '@nestjs/jwt';
|
|
import { PassportModule } from '@nestjs/passport';
|
|
import { ScheduleModule } from '@nestjs/schedule';
|
|
|
|
// Infrastructure
|
|
import { PrismaService } from './infrastructure/persistence/prisma/prisma.service';
|
|
import { UserAccountMapper } from './infrastructure/persistence/mappers/user-account.mapper';
|
|
import { UserAccountRepositoryImpl } from './infrastructure/persistence/repositories/user-account.repository.impl';
|
|
import { RedisModule } from './infrastructure/redis/redis.module';
|
|
import { KafkaModule } from './infrastructure/kafka/kafka.module';
|
|
import { WalletGeneratorService } from './infrastructure/external/blockchain/wallet-generator.service';
|
|
import { SmsService } from './infrastructure/external/sms/sms.service';
|
|
|
|
// Domain
|
|
import { USER_ACCOUNT_REPOSITORY } from './domain/repositories/user-account.repository.interface';
|
|
import { UserValidatorService } from './domain/services/user-validator.service';
|
|
|
|
// Application
|
|
import { TokenService } from './application/services/token.service';
|
|
import { AutoCreateAccountHandler } from './application/commands/auto-create-account/auto-create-account.handler';
|
|
import { RecoverByMnemonicHandler } from './application/commands/recover-by-mnemonic/recover-by-mnemonic.handler';
|
|
import { RecoverByPhoneHandler } from './application/commands/recover-by-phone/recover-by-phone.handler';
|
|
|
|
// API
|
|
import { UserAccountController } from './api/controllers/user-account.controller';
|
|
|
|
// Shared
|
|
import { JwtStrategy } from './shared/strategies/jwt.strategy';
|
|
import { JwtAuthGuard } from './shared/guards/jwt-auth.guard';
|
|
|
|
const CommandHandlers = [
|
|
AutoCreateAccountHandler,
|
|
RecoverByMnemonicHandler,
|
|
RecoverByPhoneHandler,
|
|
];
|
|
|
|
const QueryHandlers = [];
|
|
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
envFilePath: ['.env', `.env.${process.env.NODE_ENV || 'development'}`],
|
|
}),
|
|
PassportModule.register({ defaultStrategy: 'jwt' }),
|
|
JwtModule.registerAsync({
|
|
imports: [ConfigModule],
|
|
useFactory: (configService: ConfigService) => ({
|
|
secret: configService.get('JWT_SECRET', 'default-secret'),
|
|
signOptions: {
|
|
expiresIn: configService.get('JWT_ACCESS_EXPIRATION', '2h'),
|
|
},
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
ScheduleModule.forRoot(),
|
|
CqrsModule,
|
|
RedisModule,
|
|
KafkaModule,
|
|
],
|
|
controllers: [UserAccountController],
|
|
providers: [
|
|
// Infrastructure
|
|
PrismaService,
|
|
UserAccountMapper,
|
|
{
|
|
provide: USER_ACCOUNT_REPOSITORY,
|
|
useClass: UserAccountRepositoryImpl,
|
|
},
|
|
WalletGeneratorService,
|
|
SmsService,
|
|
|
|
// Domain Services
|
|
UserValidatorService,
|
|
|
|
// Application Services
|
|
TokenService,
|
|
|
|
// Auth
|
|
JwtStrategy,
|
|
JwtAuthGuard,
|
|
|
|
// CQRS Handlers
|
|
...CommandHandlers,
|
|
...QueryHandlers,
|
|
],
|
|
exports: [PrismaService],
|
|
})
|
|
export class AppModule {}
|