Some checks failed
CI/CD Pipeline - Xpeditis PreProd / Frontend - Build & Test (push) Failing after 5m31s
CI/CD Pipeline - Xpeditis PreProd / Frontend - Docker Build & Push (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Backend - Build & Test (push) Failing after 5m42s
CI/CD Pipeline - Xpeditis PreProd / Backend - Docker Build & Push (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Deploy to PreProd Server (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Run Smoke Tests (push) Has been skipped
124 lines
4.3 KiB
TypeScript
124 lines
4.3 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { LoggerModule } from 'nestjs-pino';
|
|
import { APP_GUARD } from '@nestjs/core';
|
|
import * as Joi from 'joi';
|
|
|
|
// Import feature modules
|
|
import { AuthModule } from './application/auth/auth.module';
|
|
import { RatesModule } from './application/rates/rates.module';
|
|
import { BookingsModule } from './application/bookings/bookings.module';
|
|
import { OrganizationsModule } from './application/organizations/organizations.module';
|
|
import { UsersModule } from './application/users/users.module';
|
|
import { DashboardModule } from './application/dashboard/dashboard.module';
|
|
import { AuditModule } from './application/audit/audit.module';
|
|
import { NotificationsModule } from './application/notifications/notifications.module';
|
|
import { WebhooksModule } from './application/webhooks/webhooks.module';
|
|
import { GDPRModule } from './application/gdpr/gdpr.module';
|
|
import { CsvBookingsModule } from './application/csv-bookings.module';
|
|
import { CacheModule } from './infrastructure/cache/cache.module';
|
|
import { CarrierModule } from './infrastructure/carriers/carrier.module';
|
|
import { SecurityModule } from './infrastructure/security/security.module';
|
|
import { CsvRateModule } from './infrastructure/carriers/csv-loader/csv-rate.module';
|
|
|
|
// Import global guards
|
|
import { JwtAuthGuard } from './application/guards/jwt-auth.guard';
|
|
import { CustomThrottlerGuard } from './application/guards/throttle.guard';
|
|
|
|
@Module({
|
|
imports: [
|
|
// Configuration
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
validationSchema: Joi.object({
|
|
NODE_ENV: Joi.string().valid('development', 'production', 'test').default('development'),
|
|
PORT: Joi.number().default(4000),
|
|
DATABASE_HOST: Joi.string().required(),
|
|
DATABASE_PORT: Joi.number().default(5432),
|
|
DATABASE_USER: Joi.string().required(),
|
|
DATABASE_PASSWORD: Joi.string().required(),
|
|
DATABASE_NAME: Joi.string().required(),
|
|
REDIS_HOST: Joi.string().required(),
|
|
REDIS_PORT: Joi.number().default(6379),
|
|
REDIS_PASSWORD: Joi.string().required(),
|
|
JWT_SECRET: Joi.string().required(),
|
|
JWT_ACCESS_EXPIRATION: Joi.string().default('15m'),
|
|
JWT_REFRESH_EXPIRATION: Joi.string().default('7d'),
|
|
}),
|
|
}),
|
|
|
|
// Logging
|
|
LoggerModule.forRootAsync({
|
|
useFactory: (configService: ConfigService) => ({
|
|
pinoHttp: {
|
|
transport:
|
|
configService.get('NODE_ENV') === 'development'
|
|
? {
|
|
target: 'pino-pretty',
|
|
options: {
|
|
colorize: true,
|
|
translateTime: 'SYS:standard',
|
|
ignore: 'pid,hostname',
|
|
},
|
|
}
|
|
: undefined,
|
|
level: configService.get('NODE_ENV') === 'production' ? 'info' : 'debug',
|
|
},
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
|
|
// Database
|
|
TypeOrmModule.forRootAsync({
|
|
useFactory: (configService: ConfigService) => ({
|
|
type: 'postgres',
|
|
host: configService.get('DATABASE_HOST'),
|
|
port: configService.get('DATABASE_PORT'),
|
|
username: configService.get('DATABASE_USER'),
|
|
password: configService.get('DATABASE_PASSWORD'),
|
|
database: configService.get('DATABASE_NAME'),
|
|
entities: [__dirname + '/**/*.orm-entity{.ts,.js}'],
|
|
synchronize: false, // ✅ Force false - use migrations instead
|
|
logging: configService.get('DATABASE_LOGGING', false),
|
|
autoLoadEntities: true, // Auto-load entities from forFeature()
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
|
|
// Infrastructure modules
|
|
SecurityModule,
|
|
CacheModule,
|
|
CarrierModule,
|
|
CsvRateModule,
|
|
|
|
// Feature modules
|
|
AuthModule,
|
|
RatesModule,
|
|
BookingsModule,
|
|
CsvBookingsModule,
|
|
OrganizationsModule,
|
|
UsersModule,
|
|
DashboardModule,
|
|
AuditModule,
|
|
NotificationsModule,
|
|
WebhooksModule,
|
|
GDPRModule,
|
|
],
|
|
controllers: [],
|
|
providers: [
|
|
// Global JWT authentication guard
|
|
// All routes are protected by default, use @Public() to bypass
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: JwtAuthGuard,
|
|
},
|
|
// Global rate limiting guard
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: CustomThrottlerGuard,
|
|
},
|
|
],
|
|
})
|
|
export class AppModule {}
|