Artteiv's picture
fix: update config and import
13dd365
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@Injectable()
export class DatabaseConfigService implements TypeOrmOptionsFactory {
constructor(private readonly configService: ConfigService) {}
createTypeOrmOptions(): TypeOrmModuleOptions {
const isSslEnabled = this.configService.get('db.ssl_enabled') !== 'false';
return {
type: 'postgres',
host: this.configService.get('db.host'),
port: this.configService.get('db.port'),
username: this.configService.get('db.user_name'),
database: this.configService.get('db.name'),
password: this.configService.get('db.password'),
entities: [path.join(__dirname, '../**/*.entity{.ts,.js}')],
ssl: isSslEnabled
? {
rejectUnauthorized: false,
}
: false,
maxQueryExecutionTime: this.configService.get('db.slow_limit'),
};
}
}