FactuGES_ERP/modules/companies/src/api/infrastructure/di/companies.di.ts

129 lines
4.0 KiB
TypeScript
Raw Normal View History

2026-07-06 10:57:33 +00:00
import { buildTransactionManager, type ModuleParams, type SetupParams } from "@erp/core/api";
import type { IIdentityPublicServices } from "@erp/identity/api";
import type { Sequelize } from "sequelize";
import {
feat: add proforma customer change evaluation utility - Implemented `evaluateProformaCustomerChange` function to assess changes in customer details for proforma invoices. - Introduced types for customer change details, blockers, field differences, and fiscal targets. - Added utility functions for normalizing text and formatting recipient information. test: add unit tests for customer payment resolver - Created tests for `CustomerPaymentResolver` to validate payment term retrieval and handling of inactive terms. - Ensured proper behavior when clearing payment terms and handling non-existent terms. test: add unit tests for customer default payment term resolver - Developed tests for `CustomerDefaultPaymentTermResolver` to verify default payment term resolution logic. - Included scenarios for creating customers with and without explicit payment term IDs. feat: implement customer default payment term resolver - Created `CustomerDefaultPaymentTermResolver` to manage default payment term resolution during customer creation. - Integrated with company finder and payment resolver services. test: add unit tests for create customer use case - Implemented tests for `CreateCustomerUseCase` to ensure correct handling of payment term IDs during customer creation. - Validated behavior when no explicit payment term ID is provided. test: add unit tests for update customer use case - Developed tests for `UpdateCustomerUseCase` to verify payment term handling during customer updates. - Ensured that inactive payment terms are not assigned and that explicit null values are respected. feat: add dependency injection for customer company services - Implemented DI for customer company dependencies to facilitate service resolution. test: add tests for customer create data utility - Created tests for `buildCustomerCreateData` to validate payment term handling based on user input.
2026-08-17 09:25:34 +00:00
CompanyPaymentTermResolver,
2026-07-06 10:57:33 +00:00
CompanyCreator,
CompanyFinder,
CompanyPublicFinder,
CompanyPublicModelMapper,
CompanyStatusChanger,
CompanyUpdater,
CreateCompanyUseCase,
DisableCompanyUseCase,
EnableCompanyUseCase,
FindAvailableCompaniesForAccountUseCase,
GetCompanyByIdUseCase,
GetCurrentCompanyUseCase,
2026-07-06 10:57:33 +00:00
type ICompanyPublicServices,
UpdateCompanyUseCase,
UpdateCurrentCompanyUseCase,
2026-07-06 10:57:33 +00:00
buildCompanyPublicServices,
} from "../../application";
import { SequelizeCompanyDomainMapper, SequelizeCompanyRepository } from "../persistence";
feat: add proforma customer change evaluation utility - Implemented `evaluateProformaCustomerChange` function to assess changes in customer details for proforma invoices. - Introduced types for customer change details, blockers, field differences, and fiscal targets. - Added utility functions for normalizing text and formatting recipient information. test: add unit tests for customer payment resolver - Created tests for `CustomerPaymentResolver` to validate payment term retrieval and handling of inactive terms. - Ensured proper behavior when clearing payment terms and handling non-existent terms. test: add unit tests for customer default payment term resolver - Developed tests for `CustomerDefaultPaymentTermResolver` to verify default payment term resolution logic. - Included scenarios for creating customers with and without explicit payment term IDs. feat: implement customer default payment term resolver - Created `CustomerDefaultPaymentTermResolver` to manage default payment term resolution during customer creation. - Integrated with company finder and payment resolver services. test: add unit tests for create customer use case - Implemented tests for `CreateCustomerUseCase` to ensure correct handling of payment term IDs during customer creation. - Validated behavior when no explicit payment term ID is provided. test: add unit tests for update customer use case - Developed tests for `UpdateCustomerUseCase` to verify payment term handling during customer updates. - Ensured that inactive payment terms are not assigned and that explicit null values are respected. feat: add dependency injection for customer company services - Implemented DI for customer company dependencies to facilitate service resolution. test: add tests for customer create data utility - Created tests for `buildCustomerCreateData` to validate payment term handling based on user input.
2026-08-17 09:25:34 +00:00
import { resolveCompanyCatalogsDeps } from "./company-catalog-deps.di";
2026-07-06 10:57:33 +00:00
export type CompaniesInternalDeps = {
repository: SequelizeCompanyRepository;
publicFinder: CompanyPublicFinder;
useCases: {
createCompany: () => CreateCompanyUseCase;
getCompanyById: () => GetCompanyByIdUseCase;
getCurrentCompany: () => GetCurrentCompanyUseCase;
2026-07-06 10:57:33 +00:00
findAvailableCompaniesForAccount: () => FindAvailableCompaniesForAccountUseCase;
updateCompany: () => UpdateCompanyUseCase;
updateCurrentCompany: () => UpdateCurrentCompanyUseCase;
2026-07-06 10:57:33 +00:00
enableCompany: () => EnableCompanyUseCase;
disableCompany: () => DisableCompanyUseCase;
};
};
export const buildCompaniesDependencies = (params: ModuleParams): CompaniesInternalDeps => {
2026-08-24 21:43:00 +00:00
const { database, getService, transactionContext } = params;
const transactionManager = buildTransactionManager(database as Sequelize, transactionContext);
2026-07-06 10:57:33 +00:00
const responseMapper = new CompanyPublicModelMapper();
const identityServices = getService<IIdentityPublicServices>("identity:general");
feat: add proforma customer change evaluation utility - Implemented `evaluateProformaCustomerChange` function to assess changes in customer details for proforma invoices. - Introduced types for customer change details, blockers, field differences, and fiscal targets. - Added utility functions for normalizing text and formatting recipient information. test: add unit tests for customer payment resolver - Created tests for `CustomerPaymentResolver` to validate payment term retrieval and handling of inactive terms. - Ensured proper behavior when clearing payment terms and handling non-existent terms. test: add unit tests for customer default payment term resolver - Developed tests for `CustomerDefaultPaymentTermResolver` to verify default payment term resolution logic. - Included scenarios for creating customers with and without explicit payment term IDs. feat: implement customer default payment term resolver - Created `CustomerDefaultPaymentTermResolver` to manage default payment term resolution during customer creation. - Integrated with company finder and payment resolver services. test: add unit tests for create customer use case - Implemented tests for `CreateCustomerUseCase` to ensure correct handling of payment term IDs during customer creation. - Validated behavior when no explicit payment term ID is provided. test: add unit tests for update customer use case - Developed tests for `UpdateCustomerUseCase` to verify payment term handling during customer updates. - Ensured that inactive payment terms are not assigned and that explicit null values are respected. feat: add dependency injection for customer company services - Implemented DI for customer company dependencies to facilitate service resolution. test: add tests for customer create data utility - Created tests for `buildCustomerCreateData` to validate payment term handling based on user input.
2026-08-17 09:25:34 +00:00
const catalogsDeps = resolveCompanyCatalogsDeps(params);
2026-07-06 10:57:33 +00:00
const repository = new SequelizeCompanyRepository(new SequelizeCompanyDomainMapper(), database);
const finder = new CompanyFinder(repository);
const creator = new CompanyCreator(repository);
feat: add proforma customer change evaluation utility - Implemented `evaluateProformaCustomerChange` function to assess changes in customer details for proforma invoices. - Introduced types for customer change details, blockers, field differences, and fiscal targets. - Added utility functions for normalizing text and formatting recipient information. test: add unit tests for customer payment resolver - Created tests for `CustomerPaymentResolver` to validate payment term retrieval and handling of inactive terms. - Ensured proper behavior when clearing payment terms and handling non-existent terms. test: add unit tests for customer default payment term resolver - Developed tests for `CustomerDefaultPaymentTermResolver` to verify default payment term resolution logic. - Included scenarios for creating customers with and without explicit payment term IDs. feat: implement customer default payment term resolver - Created `CustomerDefaultPaymentTermResolver` to manage default payment term resolution during customer creation. - Integrated with company finder and payment resolver services. test: add unit tests for create customer use case - Implemented tests for `CreateCustomerUseCase` to ensure correct handling of payment term IDs during customer creation. - Validated behavior when no explicit payment term ID is provided. test: add unit tests for update customer use case - Developed tests for `UpdateCustomerUseCase` to verify payment term handling during customer updates. - Ensured that inactive payment terms are not assigned and that explicit null values are respected. feat: add dependency injection for customer company services - Implemented DI for customer company dependencies to facilitate service resolution. test: add tests for customer create data utility - Created tests for `buildCustomerCreateData` to validate payment term handling based on user input.
2026-08-17 09:25:34 +00:00
const paymentTermResolver = new CompanyPaymentTermResolver({
paymentTermFinder: catalogsDeps.paymentTerm.finder,
});
2026-07-06 10:57:33 +00:00
const updater = new CompanyUpdater({ finder, repository });
const statusChanger = new CompanyStatusChanger(repository);
const publicFinder = new CompanyPublicFinder({
repository,
mapper: responseMapper,
});
return {
repository,
publicFinder,
useCases: {
createCompany: () =>
new CreateCompanyUseCase({
creator,
responseMapper,
transactionManager,
}),
getCompanyById: () =>
new GetCompanyByIdUseCase({
finder,
responseMapper,
transactionManager,
}),
getCurrentCompany: () =>
new GetCurrentCompanyUseCase({
finder,
responseMapper,
transactionManager,
}),
2026-07-06 10:57:33 +00:00
findAvailableCompaniesForAccount: () =>
new FindAvailableCompaniesForAccountUseCase({
identityServices,
repository,
responseMapper,
transactionManager,
}),
updateCompany: () =>
new UpdateCompanyUseCase({
updater,
feat: add proforma customer change evaluation utility - Implemented `evaluateProformaCustomerChange` function to assess changes in customer details for proforma invoices. - Introduced types for customer change details, blockers, field differences, and fiscal targets. - Added utility functions for normalizing text and formatting recipient information. test: add unit tests for customer payment resolver - Created tests for `CustomerPaymentResolver` to validate payment term retrieval and handling of inactive terms. - Ensured proper behavior when clearing payment terms and handling non-existent terms. test: add unit tests for customer default payment term resolver - Developed tests for `CustomerDefaultPaymentTermResolver` to verify default payment term resolution logic. - Included scenarios for creating customers with and without explicit payment term IDs. feat: implement customer default payment term resolver - Created `CustomerDefaultPaymentTermResolver` to manage default payment term resolution during customer creation. - Integrated with company finder and payment resolver services. test: add unit tests for create customer use case - Implemented tests for `CreateCustomerUseCase` to ensure correct handling of payment term IDs during customer creation. - Validated behavior when no explicit payment term ID is provided. test: add unit tests for update customer use case - Developed tests for `UpdateCustomerUseCase` to verify payment term handling during customer updates. - Ensured that inactive payment terms are not assigned and that explicit null values are respected. feat: add dependency injection for customer company services - Implemented DI for customer company dependencies to facilitate service resolution. test: add tests for customer create data utility - Created tests for `buildCustomerCreateData` to validate payment term handling based on user input.
2026-08-17 09:25:34 +00:00
paymentTermResolver,
2026-07-06 10:57:33 +00:00
responseMapper,
transactionManager,
}),
updateCurrentCompany: () =>
new UpdateCurrentCompanyUseCase({
updater,
paymentTermResolver,
responseMapper,
transactionManager,
}),
2026-07-06 10:57:33 +00:00
enableCompany: () =>
new EnableCompanyUseCase({
finder,
changer: statusChanger,
responseMapper,
transactionManager,
}),
disableCompany: () =>
new DisableCompanyUseCase({
finder,
changer: statusChanger,
responseMapper,
transactionManager,
}),
},
};
};
export const buildCompaniesPublicServices = (
_params: SetupParams,
deps: CompaniesInternalDeps
): ICompanyPublicServices => {
return buildCompanyPublicServices(deps.publicFinder);
};