db initialize through env flag
This commit is contained in:
parent
2a45c0b522
commit
18f95a93e7
@ -55,7 +55,7 @@ export class AuthController {
|
||||
|
||||
@UseInterceptors(LogoutInterceptor)
|
||||
@HttpCode(200)
|
||||
@Post('logout')
|
||||
@Post('1/logout')
|
||||
async logout(@Req() req: any, @Res() res: Response) {
|
||||
const refreshToken = req.user?.refreshToken;
|
||||
let rst: any = await this.authService.logoutUser(refreshToken);
|
||||
@ -74,7 +74,7 @@ export class AuthController {
|
||||
res.json({ ...rst })
|
||||
}
|
||||
|
||||
@Get('refresh-tokens')
|
||||
@Get('1/refresh-tokens')
|
||||
async getTokenFromRefreshToken(@Req() req: Request, @Res({ passthrough: true }) res: Response) {
|
||||
let k: any = await this.authService.getTokenFromRefreshToken(req)
|
||||
|
||||
@ -103,7 +103,7 @@ export class AuthController {
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('sa')
|
||||
@Post('sendmail')
|
||||
@Post('1/sendmail')
|
||||
@HttpCode(200)
|
||||
async sendMail(@Body() body: SendMailDTO) {
|
||||
// let token = await this.jwtService.generateToken({ email: mail })
|
||||
|
||||
@ -12,10 +12,12 @@ export class OracleDBService {
|
||||
private readonly logger = new Logger(OracleDBService.name);
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
this.initializePool().catch(err => {
|
||||
this.logger.error('Error initializing Oracle DB pool', err);
|
||||
throw new InternalServerException();
|
||||
});
|
||||
if (process.env.DB_FOR === "ORACLE") {
|
||||
this.initializePool().catch(err => {
|
||||
this.logger.error('Error initializing Oracle DB pool', err);
|
||||
throw new InternalServerException();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async initializePool(): Promise<void> {
|
||||
@ -63,54 +65,19 @@ export class OracleDBService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class MssqlDBService {
|
||||
private pool: ConnectionPool;
|
||||
private poolConnected = false;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
const config: any = getMssqlConfig(configService);
|
||||
this.pool = new ConnectionPool({
|
||||
...config,
|
||||
pool: {
|
||||
max: 10,
|
||||
min: 0,
|
||||
idleTimeoutMillis: 30000,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getConnection(): Promise<ConnectionPool> {
|
||||
try {
|
||||
if (!this.poolConnected) {
|
||||
this.pool.on('error', err => {
|
||||
console.error('SQL Pool Error:', err);
|
||||
this.poolConnected = false;
|
||||
});
|
||||
|
||||
await this.pool.connect();
|
||||
this.poolConnected = true;
|
||||
}
|
||||
return this.pool;
|
||||
} catch (error) {
|
||||
console.error('Failed to get connection from pool:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class PgDBService implements OnModuleDestroy {
|
||||
private pool: pgPool | null = null;
|
||||
private readonly logger = new Logger(PgDBService.name);
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
this.initializePool().catch(err => {
|
||||
this.logger.error('Error initializing PostgreSQL DB pool', err);
|
||||
// Re-throw to indicate a critical startup failure, preventing the application from starting
|
||||
throw new InternalServerException('Failed to initialize database pool');
|
||||
});
|
||||
if (process.env.DB_FOR === "PG") {
|
||||
this.initializePool().catch(err => {
|
||||
this.logger.error('Error initializing PostgreSQL DB pool', err);
|
||||
// Re-throw to indicate a critical startup failure, preventing the application from starting
|
||||
throw new InternalServerException('Failed to initialize database pool');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,3 +167,39 @@ export class PgDBService implements OnModuleDestroy {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class MssqlDBService {
|
||||
private pool: ConnectionPool;
|
||||
private poolConnected = false;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
const config: any = getMssqlConfig(configService);
|
||||
this.pool = new ConnectionPool({
|
||||
...config,
|
||||
pool: {
|
||||
max: 10,
|
||||
min: 0,
|
||||
idleTimeoutMillis: 30000,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getConnection(): Promise<ConnectionPool> {
|
||||
try {
|
||||
if (!this.poolConnected) {
|
||||
this.pool.on('error', err => {
|
||||
console.error('SQL Pool Error:', err);
|
||||
this.poolConnected = false;
|
||||
});
|
||||
|
||||
await this.pool.connect();
|
||||
this.poolConnected = true;
|
||||
}
|
||||
return this.pool;
|
||||
} catch (error) {
|
||||
console.error('Failed to get connection from pool:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user