2026-02-08 22:14:00 +00:00
|
|
|
import type { IModuleServer } from "@erp/core/api";
|
2026-02-07 22:07:23 +00:00
|
|
|
|
2026-03-16 17:45:45 +00:00
|
|
|
import { type CustomerPublicServices, customersRouter, models } from "./infrastructure";
|
|
|
|
|
import {
|
|
|
|
|
type CustomersInternalDeps,
|
|
|
|
|
buildCustomerServices,
|
|
|
|
|
buildCustomersDependencies,
|
|
|
|
|
} from "./infrastructure/di";
|
2025-07-07 18:25:13 +00:00
|
|
|
|
2025-09-09 15:48:12 +00:00
|
|
|
export * from "./infrastructure/sequelize";
|
|
|
|
|
|
2026-03-16 17:45:45 +00:00
|
|
|
export type { CustomerPublicServices };
|
|
|
|
|
|
2025-07-07 18:25:13 +00:00
|
|
|
export const customersAPIModule: IModuleServer = {
|
|
|
|
|
name: "customers",
|
|
|
|
|
version: "1.0.0",
|
|
|
|
|
dependencies: [],
|
|
|
|
|
|
2026-02-08 22:14:00 +00:00
|
|
|
/**
|
|
|
|
|
* Fase de SETUP
|
|
|
|
|
* ----------------
|
|
|
|
|
* - Construye el dominio (una sola vez)
|
|
|
|
|
* - Define qué expone el módulo
|
|
|
|
|
* - NO conecta infraestructura
|
|
|
|
|
*/
|
|
|
|
|
async setup(params) {
|
|
|
|
|
const { env: ENV, app, database, baseRoutePath: API_BASE_PATH, logger } = params;
|
|
|
|
|
|
2026-03-07 18:27:23 +00:00
|
|
|
// 1) Dominio interno
|
2026-03-16 17:45:45 +00:00
|
|
|
const internal = buildCustomersDependencies(params);
|
2026-03-07 18:27:23 +00:00
|
|
|
|
|
|
|
|
// 2) Servicios públicos (Application Services)
|
2026-03-16 17:45:45 +00:00
|
|
|
const customersServices: CustomerPublicServices = buildCustomerServices(params, internal);
|
2026-03-07 18:27:23 +00:00
|
|
|
|
2025-07-07 18:25:13 +00:00
|
|
|
logger.info("🚀 Customers module dependencies registered", {
|
2025-09-03 10:41:12 +00:00
|
|
|
label: this.name,
|
2025-07-07 18:25:13 +00:00
|
|
|
});
|
2026-03-07 18:27:23 +00:00
|
|
|
|
2025-07-07 18:25:13 +00:00
|
|
|
return {
|
2026-02-08 22:14:00 +00:00
|
|
|
// Modelos Sequelize del módulo
|
2025-08-11 17:49:52 +00:00
|
|
|
models,
|
2026-02-08 22:14:00 +00:00
|
|
|
|
|
|
|
|
// Servicios expuestos a otros módulos
|
2026-03-16 17:45:45 +00:00
|
|
|
services: {
|
|
|
|
|
general: customersServices, // 'customers:general'
|
|
|
|
|
},
|
|
|
|
|
|
2026-02-08 22:14:00 +00:00
|
|
|
// Implementación privada del módulo
|
2026-03-16 17:45:45 +00:00
|
|
|
internal,
|
2025-07-07 18:25:13 +00:00
|
|
|
};
|
|
|
|
|
},
|
2026-02-08 22:14:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fase de START
|
|
|
|
|
* -------------
|
|
|
|
|
* - Conecta el módulo al runtime
|
|
|
|
|
* - Puede usar servicios e internals ya construidos
|
|
|
|
|
* - NO construye dominio
|
|
|
|
|
*/
|
|
|
|
|
async start(params) {
|
|
|
|
|
const { app, baseRoutePath, logger, getInternal } = params;
|
|
|
|
|
|
|
|
|
|
// Recuperamos el dominio interno del módulo
|
2026-03-07 21:39:21 +00:00
|
|
|
const customersInternalDeps = getInternal<CustomersInternalDeps>("customers");
|
2026-02-08 22:14:00 +00:00
|
|
|
|
|
|
|
|
// Registro de rutas HTTP
|
2026-03-07 18:27:23 +00:00
|
|
|
customersRouter(params, customersInternalDeps);
|
2026-02-08 22:14:00 +00:00
|
|
|
|
|
|
|
|
logger.info("🚀 Customers module started", {
|
|
|
|
|
label: this.name,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Warmup opcional (si lo necesitas en el futuro)
|
|
|
|
|
* ----------------------------------------------
|
|
|
|
|
* warmup(params) {
|
|
|
|
|
* ...
|
|
|
|
|
* }
|
|
|
|
|
*/
|
2025-07-07 18:25:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default customersAPIModule;
|