45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { AppController } from './app.controller';
|
|
import { AppService } from './app.service';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { UserModule } from './user/user.module';
|
|
import { AuthModule } from './auth/auth.module';
|
|
import { User } from './entity/user';
|
|
import { UserGroup } from './entity/user-group';
|
|
import { UserRole } from './entity/user-role';
|
|
|
|
const moduleTypeOrm = TypeOrmModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => {
|
|
// console.log("config Service", configService)
|
|
return {
|
|
type: 'postgres',
|
|
host: configService.get<string>('DATABASE_HOST'),
|
|
port: parseInt(configService.get<string>('DATABASE_PORT') as string, 10),
|
|
username: configService.get<string>('DATABASE_USER'),
|
|
password: configService.get<string>('DATABASE_PASS'),
|
|
database: configService.get<string>('DATABASE_NAME'),
|
|
entities: [User, UserGroup, UserRole],
|
|
logging: true,
|
|
// synchronize: true,
|
|
};
|
|
},
|
|
});
|
|
|
|
const envFilePath =
|
|
process.env.NODE_ENV === 'test' ? '.env.e2e' : '.env';
|
|
|
|
// throw new Error("envFilePath:"+envFilePath);
|
|
const moduleConfig = ConfigModule.forRoot({
|
|
envFilePath,
|
|
});
|
|
|
|
@Module({
|
|
imports: [moduleConfig, moduleTypeOrm, UserModule, AuthModule],
|
|
controllers: [AppController],
|
|
providers: [AppService],
|
|
})
|
|
export class AppModule {}
|