db initialize through env flag
This commit is contained in:
parent
2a45c0b522
commit
c08b8bb19f
@ -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,11 +12,13 @@ export class OracleDBService {
|
||||
private readonly logger = new Logger(OracleDBService.name);
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
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> {
|
||||
try {
|
||||
@ -63,55 +65,20 @@ 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) {
|
||||
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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the PostgreSQL connection 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import { RolesGuard } from 'src/guards/roles.guard';
|
||||
@ApiTags('Manage Clients - PG')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('sa')
|
||||
@Controller('1')
|
||||
@Controller('2')
|
||||
export class ManageClientsController {
|
||||
constructor(private readonly manageClientsService: ManageClientsService) { }
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import { RolesGuard } from 'src/guards/roles.guard';
|
||||
@ApiTags('Manage Holders - PG')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('ca', 'sa')
|
||||
@Controller('manage-holder')
|
||||
@Controller('2')
|
||||
export class ManageHolderController {
|
||||
|
||||
constructor(private readonly manageHoldersService: ManageHolderService) { }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user