import { MiddlewareConsumer , Module , NestModule } from '@nestjs/common' ; import { EmailModule } from '../email' ; import { ConfigModule } from '../config' ; import { TypeOrmModule , TypeOrmModuleOptions } from '@nestjs/typeorm' ; import { APP_INTERCEPTOR } from '@nestjs/core' ; import { LoggingInterceptor , TransformInterceptor } from './interceptors' ; import { RequestContextMiddleware } from './context' ; import { ConfigService } from '../config' ; import { environment as env } from '@env-api/environment' ; import { User } from '../user' ; import { Image } from '../user/profile/image.entity' ; import { Profile } from '../user/profile/profile.entity' ; import { Project } from '../project/project.entity' ; import { Cluster } from '../project/cluster/cluster.entity' ; import { Notification } from '../notifications/notification/notification.entity' ; import { Subscription } from '../notifications/subscription/subscription.entity' ; export function isClass ( obj ) { return ! ! obj . prototype && ! ! obj . prototype . constructor . name ; } function requireAllClasses ( rc ) { return rc . keys ( ) . flatMap ( ( key ) => Object . values ( rc ( key ) ) ) . filter ( isClass ) ; } const entities = [ User , Notification , Subscription , Profile , Image , Project , Cluster ] ; @ Module ( { imports : [ ConfigModule , EmailModule . forRoot ( env . email ) , TypeOrmModule . forRootAsync ( { imports : [ ConfigModule ] , useFactory : ( config ) : TypeOrmModuleOptions => ( { ... env . database , entities , } ) , inject : [ ConfigService ] , } ) , ] , controllers : [ ] , providers : [ { provide : APP_INTERCEPTOR , useClass : TransformInterceptor , } , ] , } ) export class CoreModule implements NestModule { configure ( consumer ) { consumer . apply ( RequestContextMiddleware ) . forRoutes ( '*' ) ; } }