30 lines
No EOL
1.1 KiB
TypeScript
30 lines
No EOL
1.1 KiB
TypeScript
/**
|
|
* 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;
|
|
} |