11import { ApolloDriver , ApolloDriverConfig } from '@nestjs/apollo' ;
22import { Module } from '@nestjs/common' ;
3- import { ConfigModule } from '@nestjs/config' ;
3+ import { ConfigModule , ConfigService } from '@nestjs/config' ;
4+ import { EnvironmentVariables } from './config/env.validation' ;
45import { GraphQLModule } from '@nestjs/graphql' ;
56import { TypeOrmModule } from '@nestjs/typeorm' ;
67import { join } from 'path' ;
@@ -16,14 +17,18 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
1617import { LoggingInterceptor } from 'src/interceptor/LoggingInterceptor' ;
1718import { PromptToolModule } from './prompt-tool/prompt-tool.module' ;
1819import { MailModule } from './mail/mail.module' ;
20+ import { GitHubModule } from './github/github.module' ;
21+ import { AppConfigService } from './config/config.service' ;
22+ import { getDatabaseConfig } from './database.config' ;
1923
20- // TODO(Sma1lboy): move to a separate file
21- function isProduction ( ) : boolean {
22- return process . env . NODE_ENV === 'production' ;
23- }
2424@Module ( {
2525 imports : [
26- ConfigModule . forRoot ( { isGlobal : true } ) ,
26+ ConfigModule . forRoot ( {
27+ isGlobal : true ,
28+ validate : ( config : Record < string , unknown > ) => {
29+ return Object . assign ( new EnvironmentVariables ( ) , config ) ;
30+ } ,
31+ } ) ,
2732 GraphQLModule . forRoot < ApolloDriverConfig > ( {
2833 driver : ApolloDriver ,
2934 autoSchemaFile : join ( process . cwd ( ) , '../frontend/src/graphql/schema.gql' ) ,
@@ -35,11 +40,11 @@ function isProduction(): boolean {
3540 } ,
3641 context : ( { req, res } ) => ( { req, res } ) ,
3742 } ) ,
38- TypeOrmModule . forRoot ( {
39- type : 'sqlite' ,
40- database : join ( process . cwd ( ) , './database.db' ) ,
41- synchronize : ! isProduction ( ) ,
42- entities : [ __dirname + '/**/*.model{.ts,.js}' ] ,
43+ TypeOrmModule . forRootAsync ( {
44+ imports : [ ConfigModule ] ,
45+ useFactory : ( config : ConfigService < EnvironmentVariables > ) =>
46+ getDatabaseConfig ( new AppConfigService ( config ) ) ,
47+ inject : [ ConfigService ] ,
4348 } ) ,
4449 InitModule ,
4550 UserModule ,
@@ -50,13 +55,16 @@ function isProduction(): boolean {
5055 PromptToolModule ,
5156 MailModule ,
5257 TypeOrmModule . forFeature ( [ User ] ) ,
58+ GitHubModule ,
5359 ] ,
5460 providers : [
5561 AppResolver ,
62+ AppConfigService ,
5663 {
5764 provide : APP_INTERCEPTOR ,
5865 useClass : LoggingInterceptor ,
5966 } ,
6067 ] ,
68+ exports : [ AppConfigService ] ,
6169} )
6270export class AppModule { }
0 commit comments