mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
98 lines
3.7 KiB
TypeScript
98 lines
3.7 KiB
TypeScript
import { Module, OnApplicationBootstrap } from "@nestjs/common";
|
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
|
import { TypeOrmModule, TypeOrmModuleOptions } from "@nestjs/typeorm";
|
|
import { DataSource, DataSourceOptions } from "typeorm";
|
|
import { ensurePostgresSchemas } from "./config/ensure-postgres-schemas";
|
|
import { IamModule, DataSeeder } from "@tria-plc/iamapi-common";
|
|
import { SharedAuthModule } from "@tria-plc/api-common/modules/auth/shared-auth.module";
|
|
|
|
import appConfig from "./config/app.config";
|
|
import databaseConfig from "./config/database.config";
|
|
|
|
import { BookingsModule } from "./modules/bookings/bookings.module";
|
|
import { FilesModule } from "./modules/files/files.module";
|
|
import { ConsignmentsModule } from "./modules/consignments/consignments.module";
|
|
|
|
import { CustomersModule } from "./modules/customers/customers.module";
|
|
import { TrackingModule } from "./modules/tracking/tracking.module";
|
|
import { BillingModule } from "./modules/billing/billing.module";
|
|
import { NotificationsModule } from "./modules/notifications/notifications.module";
|
|
import { FileUploadSettingsModule } from "./modules/file-upload-settings/file-upload-settings.module";
|
|
import { DropdownSettingsModule } from "./modules/dropdown-settings/dropdown-settings.module";
|
|
import { OtpModule } from './modules/otp/otp.module';
|
|
import { RuleEngineModule } from "./modules/rule-engine/rule-engine.module";
|
|
import { BackofficeModule } from "./modules/backoffice/backoffice.module";
|
|
import { DemoPermissionsModule } from "./modules/demo-permissions/demo-permissions.module";
|
|
import {
|
|
EDR_FREIGHT_APPLICATION,
|
|
EDR_FREIGHT_PERMISSIONS,
|
|
} from "./seed/edr-freight.seed";
|
|
import { EdrOrgSeeder } from "./seed/edr-org.seeder";
|
|
import { DemoUsersSeeder } from "./seed/demo-users.seeder";
|
|
//New Trains, Wangons, Container and Cargo management modules
|
|
import { TrainsModule } from "./modules/trains/trains.module";
|
|
import { WagonsModule } from './modules/wagons/wagons.module';
|
|
import { ContainersModule } from './modules/container-management/containers.module';
|
|
import { CargoesModule } from './modules/cargoes/cargoes.module';
|
|
|
|
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
load: [appConfig, databaseConfig],
|
|
}),
|
|
TypeOrmModule.forRootAsync({
|
|
inject: [ConfigService],
|
|
useFactory: (config: ConfigService): TypeOrmModuleOptions =>
|
|
config.get<TypeOrmModuleOptions>("database")!,
|
|
dataSourceFactory: async (options) => {
|
|
if (!options) {
|
|
throw new Error("Missing TypeORM DataSource options");
|
|
}
|
|
await ensurePostgresSchemas(options as DataSourceOptions);
|
|
const dataSource = new DataSource(options as DataSourceOptions);
|
|
return dataSource.initialize();
|
|
},
|
|
}),
|
|
SharedAuthModule,
|
|
IamModule.forRoot({
|
|
applications: [EDR_FREIGHT_APPLICATION],
|
|
permissions: EDR_FREIGHT_PERMISSIONS,
|
|
}),
|
|
BookingsModule,
|
|
FilesModule,
|
|
ConsignmentsModule,
|
|
TrainsModule,
|
|
CustomersModule,
|
|
TrackingModule,
|
|
BillingModule,
|
|
NotificationsModule,
|
|
FileUploadSettingsModule,
|
|
DropdownSettingsModule,
|
|
OtpModule,
|
|
RuleEngineModule,
|
|
BackofficeModule,
|
|
DemoPermissionsModule,
|
|
//New Modules
|
|
TrainsModule,
|
|
WagonsModule,
|
|
ContainersModule,
|
|
CargoesModule,
|
|
],
|
|
providers: [EdrOrgSeeder, DemoUsersSeeder],
|
|
})
|
|
export class AppModule implements OnApplicationBootstrap {
|
|
constructor(
|
|
private readonly seeder: DataSeeder,
|
|
private readonly edrOrgSeeder: EdrOrgSeeder,
|
|
private readonly demoUsersSeeder: DemoUsersSeeder,
|
|
) { }
|
|
|
|
async onApplicationBootstrap() {
|
|
await this.seeder.run();
|
|
await this.edrOrgSeeder.run();
|
|
await this.demoUsersSeeder.run();
|
|
}
|
|
}
|