removed migration files

This commit is contained in:
Boki 2025-06-22 18:43:49 -04:00
parent 80c1dcb6cb
commit 9a5e87ef4a
16 changed files with 257 additions and 207 deletions

View file

@ -1,8 +0,0 @@
/**
* Client exports for backward compatibility
*
* @deprecated Use ServiceContainer parameter instead
* This file will be removed once all routes and services are migrated
*/
export { getMongoDBClient, getPostgreSQLClient } from './migration-helper';

View file

@ -68,10 +68,6 @@ async function initializeServices() {
// Setup service-specific configuration
const serviceContainer = setupServiceContainer(config, container.resolve('serviceContainer'));
// Initialize migration helper for backward compatibility
const { setContainerForMigration } = await import('./migration-helper');
setContainerForMigration(serviceContainer);
logger.info('Migration helper initialized for backward compatibility');
// Create app with routes
app = new Hono();

View file

@ -1,30 +0,0 @@
/**
* Temporary migration helper for web-api service
* Provides backward compatibility while migrating to DI container
*
* TODO: Remove this file once all routes and services are migrated to use ServiceContainer
*/
import type { ServiceContainer } from '@stock-bot/di';
import type { MongoDBClient } from '@stock-bot/mongodb';
import type { PostgreSQLClient } from '@stock-bot/postgres';
let containerInstance: ServiceContainer | null = null;
export function setContainerForMigration(container: ServiceContainer): void {
containerInstance = container;
}
export function getMongoDBClient(): MongoDBClient {
if (!containerInstance) {
throw new Error('Container not initialized. This is a migration helper - please update the service to accept ServiceContainer parameter');
}
return containerInstance.mongodb;
}
export function getPostgreSQLClient(): PostgreSQLClient {
if (!containerInstance) {
throw new Error('Container not initialized. This is a migration helper - please update the service to accept ServiceContainer parameter');
}
return containerInstance.postgres;
}

View file

@ -5,13 +5,14 @@
import { Hono } from 'hono';
import type { IServiceContainer } from '@stock-bot/handlers';
import { healthRoutes } from './health.routes';
import { createHealthRoutes } from './health.routes';
import { createExchangeRoutes } from './exchange.routes';
export function createRoutes(container: IServiceContainer): Hono {
const app = new Hono();
// Create routes with container
const healthRoutes = createHealthRoutes(container);
const exchangeRoutes = createExchangeRoutes(container);
// Mount routes

View file

@ -1,98 +1,111 @@
/**
* Health check routes
* Health check routes factory
*/
import { Hono } from 'hono';
import { getLogger } from '@stock-bot/logger';
import { getMongoDBClient, getPostgreSQLClient } from '../clients';
import type { IServiceContainer } from '@stock-bot/handlers';
const logger = getLogger('health-routes');
export const healthRoutes = new Hono();
// Basic health check
healthRoutes.get('/', c => {
logger.debug('Basic health check requested');
export function createHealthRoutes(container: IServiceContainer) {
const healthRoutes = new Hono();
const response = {
status: 'healthy',
service: 'web-api',
timestamp: new Date().toISOString(),
};
// Basic health check
healthRoutes.get('/', c => {
logger.debug('Basic health check requested');
logger.info('Basic health check successful', { status: response.status });
return c.json(response);
});
const response = {
status: 'healthy',
service: 'web-api',
timestamp: new Date().toISOString(),
};
// Detailed health check with database connectivity
healthRoutes.get('/detailed', async c => {
logger.debug('Detailed health check requested');
logger.info('Basic health check successful', { status: response.status });
return c.json(response);
});
const health = {
status: 'healthy',
service: 'web-api',
timestamp: new Date().toISOString(),
checks: {
mongodb: { status: 'unknown', message: '' },
postgresql: { status: 'unknown', message: '' },
},
};
// Detailed health check with database connectivity
healthRoutes.get('/detailed', async c => {
logger.debug('Detailed health check requested');
// Check MongoDB
logger.debug('Checking MongoDB connectivity');
try {
const mongoClient = getMongoDBClient();
if (mongoClient.connected) {
// Try a simple operation
const db = mongoClient.getDatabase();
await db.admin().ping();
health.checks.mongodb = { status: 'healthy', message: 'Connected and responsive' };
logger.debug('MongoDB health check passed');
} else {
health.checks.mongodb = { status: 'unhealthy', message: 'Not connected' };
logger.warn('MongoDB health check failed - not connected');
const health = {
status: 'healthy',
service: 'web-api',
timestamp: new Date().toISOString(),
checks: {
mongodb: { status: 'unknown', message: '' },
postgresql: { status: 'unknown', message: '' },
},
};
// Check MongoDB
logger.debug('Checking MongoDB connectivity');
try {
const mongoClient = container.mongodb;
if (mongoClient && mongoClient.connected) {
// Try a simple operation
const db = mongoClient.getDatabase();
await db.admin().ping();
health.checks.mongodb = { status: 'healthy', message: 'Connected and responsive' };
logger.debug('MongoDB health check passed');
} else {
health.checks.mongodb = { status: 'unhealthy', message: 'Not connected' };
logger.warn('MongoDB health check failed - not connected');
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
health.checks.mongodb = {
status: 'unhealthy',
message: errorMessage,
};
logger.error('MongoDB health check failed', { error: errorMessage });
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
health.checks.mongodb = {
status: 'unhealthy',
message: errorMessage,
};
logger.error('MongoDB health check failed', { error: errorMessage });
}
// Check PostgreSQL
logger.debug('Checking PostgreSQL connectivity');
try {
const postgresClient = getPostgreSQLClient();
await postgresClient.query('SELECT 1');
health.checks.postgresql = { status: 'healthy', message: 'Connected and responsive' };
logger.debug('PostgreSQL health check passed');
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
health.checks.postgresql = {
status: 'unhealthy',
message: errorMessage,
};
logger.error('PostgreSQL health check failed', { error: errorMessage });
}
// Check PostgreSQL
logger.debug('Checking PostgreSQL connectivity');
try {
const postgresClient = container.postgres;
if (postgresClient) {
await postgresClient.query('SELECT 1');
health.checks.postgresql = { status: 'healthy', message: 'Connected and responsive' };
logger.debug('PostgreSQL health check passed');
} else {
health.checks.postgresql = { status: 'unhealthy', message: 'PostgreSQL client not available' };
logger.warn('PostgreSQL health check failed - client not available');
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
health.checks.postgresql = {
status: 'unhealthy',
message: errorMessage,
};
logger.error('PostgreSQL health check failed', { error: errorMessage });
}
// Overall status
const allHealthy = Object.values(health.checks).every(check => check.status === 'healthy');
health.status = allHealthy ? 'healthy' : 'unhealthy';
// Overall status
const allHealthy = Object.values(health.checks).every(check => check.status === 'healthy');
health.status = allHealthy ? 'healthy' : 'unhealthy';
const statusCode = allHealthy ? 200 : 503;
const statusCode = allHealthy ? 200 : 503;
if (allHealthy) {
logger.info('Detailed health check successful - all systems healthy', {
mongodb: health.checks.mongodb.status,
postgresql: health.checks.postgresql.status,
});
} else {
logger.warn('Detailed health check failed - some systems unhealthy', {
mongodb: health.checks.mongodb.status,
postgresql: health.checks.postgresql.status,
overallStatus: health.status,
});
}
if (allHealthy) {
logger.info('Detailed health check successful - all systems healthy', {
mongodb: health.checks.mongodb.status,
postgresql: health.checks.postgresql.status,
});
} else {
logger.warn('Detailed health check failed - some systems unhealthy', {
mongodb: health.checks.mongodb.status,
postgresql: health.checks.postgresql.status,
overallStatus: health.status,
});
}
return c.json(health, statusCode);
});
return c.json(health, statusCode);
});
return healthRoutes;
}
// Export legacy routes for backward compatibility during migration
export const healthRoutes = createHealthRoutes({} as IServiceContainer);