Uecko_ERP/modules/customers/src/api/infrastructure/dependencies.ts

79 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-09-12 10:40:52 +00:00
import type { IMapperRegistry, IPresenterRegistry, ModuleParams } from "@erp/core/api";
2025-09-12 16:23:36 +00:00
import { InMemoryMapperRegistry, SequelizeTransactionManager } from "@erp/core/api";
import {
CreateCustomerUseCase,
DeleteCustomerUseCase,
GetCustomerUseCase,
ListCustomersUseCase,
2025-09-01 14:07:59 +00:00
UpdateCustomerUseCase,
} from "../application";
2025-09-01 14:07:59 +00:00
import { CustomerService } from "../domain";
import { CustomerMapper } from "./mappers";
import { CustomerRepository } from "./sequelize";
type CustomerDeps = {
transactionManager: SequelizeTransactionManager;
2025-09-12 10:40:52 +00:00
mapperRegistry: IMapperRegistry;
presenterRegistry: IPresenterRegistry;
repo: CustomerRepository;
2025-09-01 14:07:59 +00:00
service: CustomerService;
build: {
list: () => ListCustomersUseCase;
get: () => GetCustomerUseCase;
create: () => CreateCustomerUseCase;
2025-09-01 14:07:59 +00:00
update: () => UpdateCustomerUseCase;
delete: () => DeleteCustomerUseCase;
};
};
2025-09-12 16:23:36 +00:00
const _presenterRegistry: IPresenterRegistry | null = null;
2025-09-12 10:40:52 +00:00
let _mapperRegistry: IMapperRegistry | null = null;
let _repo: CustomerRepository | null = null;
2025-09-01 14:07:59 +00:00
let _service: CustomerService | null = null;
export function getCustomerDependencies(params: ModuleParams): CustomerDeps {
const { database } = params;
const transactionManager = new SequelizeTransactionManager(database);
2025-09-12 10:40:52 +00:00
if (!_mapperRegistry) {
_mapperRegistry = new InMemoryMapperRegistry();
_mapperRegistry.registerDomainMapper("FULL", new CustomerMapper());
}
if (!_repo) _repo = new CustomerRepository({ mapperRegistry: _mapperRegistry });
if (!_service) _service = new CustomerService(_repo);
2025-09-12 16:23:36 +00:00
/*if (!_presenterRegistry) {
2025-09-12 10:40:52 +00:00
_presenterRegistry = new InMemoryPresenterRegistry();
_presenterRegistry.registerPresenters([
{
2025-09-12 16:23:36 +00:00
key: { resource: "customer", projection: "FULL" },
2025-09-12 10:40:52 +00:00
presenter: new ListCustomersAssembler(),
},
{
2025-09-12 16:23:36 +00:00
key: { resource: "customer", projection: "LIST" },
2025-09-12 10:40:52 +00:00
presenter: new GetCustomerAssembler(),
},
]);
2025-09-12 16:23:36 +00:00
}*/
return {
transactionManager,
repo: _repo,
2025-09-12 10:40:52 +00:00
mapperRegistry: _mapperRegistry,
2025-09-12 16:23:36 +00:00
//presenterRegistry: _presenterRegistry,
service: _service,
2025-09-12 10:40:52 +00:00
build: {
2025-09-12 16:23:36 +00:00
/*list: () => new ListCustomersUseCase(_service!, transactionManager!, presenterRegistry!),
get: () => new GetCustomerUseCase(_service!, transactionManager!, presenterRegistry!),
create: () => new CreateCustomerUseCase(_service!, transactionManager!, presenterRegistry!),
update: () => new UpdateCustomerUseCase(_service!, transactionManager!, presenterRegistry!),
delete: () => new DeleteCustomerUseCase(_service!, transactionManager!),*/
},
};
}