Remove database
Some checks failed
Build and Push to Registry / build-and-push (push) Failing after 40s

This commit is contained in:
Sosthene 2025-09-10 15:51:44 +02:00
parent cfa9514be9
commit b04679ba34
3 changed files with 33 additions and 148 deletions

View File

@ -1,7 +1,6 @@
import { Request, Response } from 'express';
import { v4 as uuidv4 } from 'uuid';
import { Database } from '../database';
import { SignerImprovedService } from '../services/signer-improved';
import { SignerImprovedService } from '../services/signer';
import { SessionManager } from '../utils/session-manager';
import { authTokens } from '../utils/auth-tokens';
import { ProcessInfo, ProcessData, ProcessRoles, EOfficeStatus } from '../types';
@ -54,22 +53,23 @@ export class ProcessController {
});
// Get UUID from database
let uuid: string;
try {
const result = await Database.query('SELECT uid FROM users WHERE "idNot" = $1', [userAuth.idNotUser.idNot]);
uuid = result.rows.length > 0 ? result.rows[0].uid : null;
} catch (error) {
Logger.error('Error fetching UUID by idNot', {
requestId,
error: error instanceof Error ? error.message : 'Unknown error'
});
uuid = '';
}
let uuid: string = uuidv4();
// TODO this should be moved to signer probably
// try {
// const result = await Database.query('SELECT uid FROM users WHERE "idNot" = $1', [userAuth.idNotUser.idNot]);
// uuid = result.rows.length > 0 ? result.rows[0].uid : null;
// } catch (error) {
// Logger.error('Error fetching UUID by idNot', {
// requestId,
// error: error instanceof Error ? error.message : 'Unknown error'
// });
// uuid = '';
// }
if (!uuid) {
Logger.info('No existing UUID found in db, generating new one', { requestId });
uuid = uuidv4();
}
// if (!uuid) {
// Logger.info('No existing UUID found in db, generating new one', { requestId });
// uuid = uuidv4();
// }
const processData: ProcessData = {
uid: uuid,
@ -282,22 +282,22 @@ export class ProcessController {
}
// Get UUID from database
let uuid: string;
try {
const result = await Database.query('SELECT uid FROM offices WHERE "idNot" = $1', [userAuth.idNotUser.office.idNot]);
uuid = result.rows.length > 0 ? result.rows[0].uid : null;
} catch (error) {
Logger.error('Error fetching office UUID by idNot', {
requestId,
error: error instanceof Error ? error.message : 'Unknown error'
});
uuid = '';
}
let uuid: string = uuidv4();
// try {
// const result = await Database.query('SELECT uid FROM offices WHERE "idNot" = $1', [userAuth.idNotUser.office.idNot]);
// uuid = result.rows.length > 0 ? result.rows[0].uid : null;
// } catch (error) {
// Logger.error('Error fetching office UUID by idNot', {
// requestId,
// error: error instanceof Error ? error.message : 'Unknown error'
// });
// uuid = '';
// }
if (!uuid) {
Logger.info('No existing office UUID found in db, generating new one', { requestId });
uuid = uuidv4();
}
// if (!uuid) {
// Logger.info('No existing office UUID found in db, generating new one', { requestId });
// uuid = uuidv4();
// }
const processData: ProcessData = {
uid: uuid,

View File

@ -1,103 +0,0 @@
import { Pool, QueryResult, PoolConfig } from 'pg';
import * as dotenv from 'dotenv';
dotenv.config();
/**
* Configuration de la base de données PostgreSQL
*/
const dbConfig: PoolConfig = {
user: process.env.DB_USER || 'postgres',
host: process.env.DB_HOST || 'localhost',
database: process.env.DB_NAME || 'prd',
password: process.env.DB_PASSWORD || 'admin',
port: parseInt(process.env.DB_PORT || '5432'),
// Configuration du pool de connexions
max: parseInt(process.env.DB_POOL_MAX || '20'), // Nombre maximum de connexions dans le pool
min: parseInt(process.env.DB_POOL_MIN || '2'), // Nombre minimum de connexions maintenues
idleTimeoutMillis: parseInt(process.env.DB_IDLE_TIMEOUT || '30000'), // Temps d'inactivité avant fermeture
connectionTimeoutMillis: parseInt(process.env.DB_CONNECTION_TIMEOUT || '2000'), // Timeout pour établir une connexion
// acquireTimeoutMillis: parseInt(process.env.DB_ACQUIRE_TIMEOUT || '60000'), // Timeout pour acquérir une connexion
// Configuration SSL si nécessaire
ssl: process.env.DB_SSL === 'true' ? {
rejectUnauthorized: process.env.DB_SSL_REJECT_UNAUTHORIZED !== 'false'
} : false
};
/**
* Pool de connexions PostgreSQL
*/
const pool = new Pool(dbConfig);
/**
* Gestionnaire d'erreur pour le pool
*/
pool.on('error', (err: Error) => {
console.error('PostgreSQL Error:', err);
});
/**
* Classe pour gérer les opérations de base de données
*/
export class Database {
/**
* Exécute une requête SQL avec des paramètres
* @param text - La requête SQL
* @param params - Les paramètres de la requête
* @returns Promise<QueryResult> - Le résultat de la requête
*/
static async query(text: string, params?: any[]): Promise<QueryResult> {
try {
return await pool.query(text, params);
} catch (error) {
console.error('Error executing query:', error);
throw error;
}
}
/**
* Teste la connexion à la base de données
* @returns Promise<boolean> - True si la connexion est réussie
*/
static async testConnection(): Promise<boolean> {
try {
const result = await this.query('SELECT NOW() as current_time');
console.log('Database connection successful:', result.rows[0].current_time);
return true;
} catch (error: any) {
console.error('Database connection failed:', error.message);
return false;
}
}
/**
* Ferme toutes les connexions du pool
* @returns Promise<void>
*/
static async close(): Promise<void> {
try {
await pool.end();
console.log('PostgreSQL connection pool closed');
} catch (error) {
console.error('Error closing connection pool:', error);
}
}
}
/**
* Gestion propre de l'arrêt de l'application
*/
process.on('SIGINT', async () => {
console.log('SIGINT signal received, closing connections...');
await Database.close();
process.exit(0);
});
process.on('SIGTERM', async () => {
console.log('SIGTERM signal received, closing connections...');
await Database.close();
process.exit(0);
});

View File

@ -1,6 +1,5 @@
import express from 'express';
import cors from 'cors';
import { Database } from './database';
import { config } from './config';
import { routes } from './routes';
import { SignerImprovedService } from './services/signer-improved';
@ -96,18 +95,7 @@ setInterval(() => {
// Initialisation et démarrage du serveur
async function startServer(): Promise<void> {
try {
// Test de la connexion à la base de données au démarrage
console.log('Initializing database connection...');
const isDbConnected = await Database.testConnection();
if (!isDbConnected) {
console.error('Database connection failed. Server cannot start.');
process.exit(1);
}
console.log('Database connection established successfully');
try {
// Démarrage du serveur
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);