From 877b173f0e21a61b27135834ca977186ebe97667 Mon Sep 17 00:00:00 2001 From: nfesta2023 <142601504+nfesta2023@users.noreply.github.com> Date: Sun, 3 Mar 2024 15:26:07 +0700 Subject: [PATCH] apply env (#11) Co-authored-by: NHT --- .prettierrc | 3 ++- src/app.module.ts | 33 ++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.prettierrc b/.prettierrc index a20502b..9409967 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,5 @@ { "singleQuote": true, - "trailingComma": "all" + "trailingComma": "all", + "printWidth": 80 } diff --git a/src/app.module.ts b/src/app.module.ts index 76a26f1..cf03d30 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -9,25 +9,31 @@ import { OtpService } from './service/otp.service'; import { CustomerService } from './service/customer.service'; import { TypeOrmModule } from '@nestjs/typeorm'; import { Customer } from './entity/customer.entity'; -import { ConfigModule } from '@nestjs/config'; +import { ConfigModule, ConfigService } from '@nestjs/config'; // import { redisStore } from 'cache-manager-redis-yet'; import { CacheModule } from '@nestjs/cache-manager'; import { HttpModule } from '@nestjs/axios'; @Module({ imports: [ - TypeOrmModule.forRoot({ - type: 'mysql', - host: 'db-2all-free.c9s4w6ey6i0r.ap-southeast-1.rds.amazonaws.com', - port: 3306, - username: 'admin', - password: 'Goodfood4goodlife', - database: 'new-2all-dev', - entities: [Customer], - synchronize: false, - autoLoadEntities: true, + ConfigModule.forRoot({ + envFilePath: ['.env'], + }), + TypeOrmModule.forRootAsync({ + imports: [ConfigModule], + useFactory: (configService: ConfigService) => ({ + type: 'mysql', + host: configService.get('DB_HOST'), + port: configService.get('DB_PORT'), + username: configService.get('DB_USERNAME'), + password: configService.get('DB_PASSWORD'), + database: configService.get('DB_NAME'), + entities: [__dirname + '/entity/*.entity{.ts,.js}'], + synchronize: false, + autoLoadEntities: true, + }), + inject: [ConfigService], }), - ConfigModule.forRoot(), CacheModule.registerAsync({ isGlobal: true, useFactory: async () => ({ @@ -38,9 +44,6 @@ import { HttpModule } from '@nestjs/axios'; }), TypeOrmModule.forFeature([Customer]), HttpModule, - ConfigModule.forRoot({ - envFilePath: ['.env'], - }), ], controllers: [AppController, TokenController, OtpController], providers: [