Backend half
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { ICompanyRepository } from '../../../Repositories/interfaces/ICompanyRepository';
|
||||
import { CompanyQueryHandler } from './CompanyQueryHandler';
|
||||
import {
|
||||
GetCompanyByIdQuery,
|
||||
GetCompanyByNameQuery,
|
||||
GetAllCompaniesQuery,
|
||||
GetBasicCompanyByIdQuery,
|
||||
GetAllBasicCompaniesQuery
|
||||
} from './CompanyQuery';
|
||||
import { appLogger } from '../../../utils/logger';
|
||||
|
||||
export class CompanyQueryDispatcher {
|
||||
private queryHandler: CompanyQueryHandler;
|
||||
|
||||
constructor(companyRepository: ICompanyRepository) {
|
||||
appLogger.startup('Initializing CompanyQueryDispatcher...');
|
||||
this.queryHandler = new CompanyQueryHandler(companyRepository);
|
||||
appLogger.startup('CompanyQueryDispatcher initialized');
|
||||
}
|
||||
|
||||
async dispatch(query: any): Promise<any> {
|
||||
try {
|
||||
appLogger.info('Dispatching company query', {
|
||||
queryType: query.constructor.name,
|
||||
action: 'dispatch_company_query'
|
||||
});
|
||||
|
||||
switch (query.constructor) {
|
||||
case GetCompanyByIdQuery:
|
||||
return await this.queryHandler.handleGetById(query);
|
||||
|
||||
case GetCompanyByNameQuery:
|
||||
return await this.queryHandler.handleGetByName(query);
|
||||
|
||||
case GetAllCompaniesQuery:
|
||||
return await this.queryHandler.handleGetAll(query);
|
||||
|
||||
case GetBasicCompanyByIdQuery:
|
||||
return await this.queryHandler.handleGetBasicById(query);
|
||||
|
||||
case GetAllBasicCompaniesQuery:
|
||||
return await this.queryHandler.handleGetAllBasic(query);
|
||||
|
||||
default:
|
||||
const errorMessage = `Unknown query type: ${query.constructor.name}`;
|
||||
appLogger.errorEvent('Unknown company query type', 'dispatch_error', {
|
||||
queryType: query.constructor.name
|
||||
});
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
appLogger.errorEvent('Error dispatching company query', 'dispatch_error', {
|
||||
error: error.message,
|
||||
queryType: query.constructor.name
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user