Skip to content

Commit

Permalink
refactor: used config service to connect to database
Browse files Browse the repository at this point in the history
  • Loading branch information
aniebietafia committed Aug 31, 2024
1 parent c769eb4 commit f4cd2ef
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions brints-estate-api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';

import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
// import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from './auth/auth.module';
import { environmentValidationSchema } from './config/environment.validation';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: !process.env.NODE_ENV
? '.env'
: `.env.${process.env.NODE_ENV}`,
validationSchema: environmentValidationSchema,
}),
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
type: 'postgres',
host: configService.get('DB_HOST'),
port: configService.get('DB_PORT'),
username: configService.get('DB_USER'),
password: configService.get('DB_PASSWORD'),
database: configService.get('DB_NAME'),
autoLoadEntities: process.env.NODE_ENV === 'development',
synchronize: process.env.NODE_ENV === 'development',
entities: [__dirname + '/**/*.entity{.ts,.js}'],
// entities: [User, UserAuth],
}),
}),
AuthModule,
UsersModule,
// TypeOrmModule.forRootAsync({
// useFactory: () => ({
// type: 'postgres',
// host: 'localhost',
// port: 5432,
// username: 'postgres',
// password: 'postgres',
// database: 'brints-estate-backend',
// synchronize: true,
// autoLoadEntities: true,
// })
// })
],
})
export class AppModule {}

0 comments on commit f4cd2ef

Please sign in to comment.