All files / src/infrastructure/database database.module.ts

0% Statements 0/14
0% Branches 0/6
0% Functions 0/2
0% Lines 0/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { BullModule } from '@nestjs/bullmq';
 
@Module({
  imports: [
    MongooseModule.forRootAsync({
      useFactory: () => {
        const uri = process.env.MONGODB_URI;
        if (!uri) {
          throw new Error('MONGODB_URI environment variable is missing');
        }
        const isProduction = process.env.NODE_ENV === 'production';
        return {
          uri,
          autoIndex: !isProduction, // Disable automatic index creation in production
          autoCreate: !isProduction, // Disable automatic collection creation in production
        };
      },
    }),
    BullModule.forRootAsync({
      useFactory: () => {
        const host = process.env.REDIS_HOST || '127.0.0.1';
        const port = parseInt(process.env.REDIS_PORT || '6379', 10);
        return {
          connection: {
            host,
            port,
          },
        };
      },
    }),
  ],
  exports: [MongooseModule, BullModule],
})
export class DatabaseModule {}