Your IP : 216.73.216.43


Current Path : /home/deltalab/PMS/logistic-backend/src/config/database/mongo/
Upload File :
Current File : //home/deltalab/PMS/logistic-backend/src/config/database/mongo/config.service.ts

import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class MongoConfigService {
  constructor(private configService: ConfigService) {}

  get host(): string {
    return this.configService.get<string>('mongo.host');
  }

  get port(): number {
    return Number(this.configService.get<number>('mongo.port'));
  }

  get database(): string {
    return this.configService.get<string>('mongo.database');
  }

  get uri(): string {
    const host = this.configService.get<string>('mongo.host');
    const port = Number(this.configService.get<number>('mongo.port'));
    const database = this.configService.get<string>('mongo.database');
    let uri = `mongodb://${host}:${port}/${database}`;

    if (this.configService.get<string>('app.env') !== 'dev') {
      const username = this.configService.get<string>('mongo.username');
      const password = this.configService.get<string>('mongo.password');
      uri = `mongodb://${username}:${password}@${host}:${port}/${database}`;
    }

    return uri;
  }
}