Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ModelModule } from './model/model.module';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { SystemsModule } from './systems/systems.module'
import config from './config';
@Module({
imports: [MongooseModule.forRootAsync({
useFactory: async () => ({
uri: config.MONGO_URI
})
}),
ModelModule,
AuthModule,
UserModule,
SystemsModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
import { resolve } from 'path';
import { MailConfig } from 'config/mail';
@Module({
imports: [
PassportModule.register({
session: false,
}),
ConfigModule
.resolveRootPath(resolve(__dirname, '../..'))
.resolveEnvValidator(new ConfigValidate())
.forRoot(
resolve(__dirname, '..', 'config', '**', '!(*.d).{ts,js}'),
{
path: `${process.env.NODE_ENV || 'development'}.env`,
}),
MongooseModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
uri: configService.get('env.MONGODB_URI'),
useNewUrlParser: true,
}),
inject: [ConfigService],
}),
MailerModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
return configService.get('mail');
},
inject: [ConfigService],
}),
],
})
const event = new EventEmitter();
@Global()
@Module({
imports: [
ConfigModule.register(path.resolve(process.cwd(), 'dist/config', '**/!(*.d).js')),
CacheModule.registerAsync({
useFactory: (config: IConfigService) => config.get('cache'),
inject: [CONFIG_SERVICE]
}),
LoggerModule.registerAsync({
useFactory: (config: IConfigService) => config.get('logger'),
inject: [CONFIG_SERVICE]
}),
EventBusModule.register({ event }),
MongooseModule.forRootAsync({
useFactory: (config: IConfigService) => config.get('mongo.connection'),
inject: [CONFIG_SERVICE]
}),
CryptModule.registerAsync({
useFactory: (config: IConfigService) => config.get('crypt'),
inject: [CONFIG_SERVICE]
}),
NotificationModule,
CoreModule
],
providers: [ConfigProvider, CacheProvider, LoggerProvider, EventPublisherProvider, CryptProvider, NotificationProvider],
exports: [
CacheModule,
NotificationModule,
ConfigProvider,
CacheProvider,
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Configuration } from './shared/configuration/configuration.enum';
import { ConfigurationService } from './shared/configuration/configuration.service';
import { SharedModule } from './shared/shared.module';
import { TodoModule } from './todo/todo.module';
import { UserModule } from './user/user.module';
@Module({
imports: [SharedModule, MongooseModule.forRootAsync({
imports: [SharedModule],
useFactory: async (_configService: ConfigurationService) => ({
uri: _configService.get(Configuration.MONGO_URI),
retryDelay: 500,
retryAttempts: 3,
useFindAndModify: false,
useNewUrlParser: true,
useCreateIndex: true,
}),
inject: [ConfigurationService],
}), UserModule, TodoModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
static host: string;
let mongod: MongoMemoryServer;
let uri: string;
async function testDBFactory() {
mongod = new MongoMemoryServer();
uri = await mongod.getConnectionString();
await mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
});
return { uri };
}
@Module({
imports: [
MongooseModule.forRootAsync({
useFactory: testDBFactory
})
]
})
export class InMemoryDatabaseModule {
static async closeDatabase() {
await mongoose.connection.dropDatabase();
await mongoose.connection.close();
await mongod.stop();
mongod = null;
uri = null;
}
}
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { MongooseModule, MongooseModuleOptions } from '@nestjs/mongoose';
import { UsersModule } from './users/users.module';
import { AuthModule } from './auth/auth.module';
import { join } from 'path';
import { ConfigModule } from './config/config.module';
import { ConfigService } from './config/config.service';
@Module({
imports: [
MongooseModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
const options: MongooseModuleOptions = {
uri: configService.mongoUri,
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
};
if (configService.mongoAuthEnabled) {
options.user = configService.mongoUser;
options.pass = configService.mongoPassword;
}
return options;