2026-10-03 10:36:03 +00:00
|
|
|
import type { RequestHandler } from "express";
|
|
|
|
|
import type { Sequelize } from "sequelize";
|
|
|
|
|
|
2026-10-03 13:19:20 +00:00
|
|
|
import { AccessUseCases } from "./application/access.use-cases";
|
2026-10-03 10:36:03 +00:00
|
|
|
import { CompanyUseCases } from "./application/company.use-cases";
|
|
|
|
|
import { CompanyInputMapper } from "./application/company-input.mapper";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { FolderMappingUseCases } from "./application/folder-mapping.use-cases";
|
2026-10-04 21:06:07 +00:00
|
|
|
import type { IMailInventoryService } from "./application/mail-configuration.repository";
|
|
|
|
|
import { MailConfigurationUseCases } from "./application/mail-configuration.use-cases";
|
2026-10-05 08:45:02 +00:00
|
|
|
import { MailboxUseCases } from "./application/mailbox.use-cases";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { PrinterConfigurationUseCases } from "./application/printer-configuration.use-cases";
|
2026-10-05 07:53:29 +00:00
|
|
|
import type { IWorkProfileInventoryService } from "./application/work-profile.repository";
|
|
|
|
|
import { WorkProfileUseCases } from "./application/work-profile.use-cases";
|
2026-10-03 13:19:20 +00:00
|
|
|
import { registerAccessRoutes } from "./infrastructure/http/access.routes";
|
2026-10-03 10:36:03 +00:00
|
|
|
import { registerCompanyRoutes } from "./infrastructure/http/company.routes";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { registerFolderMappingRoutes } from "./infrastructure/http/folder-mapping.routes";
|
2026-10-04 21:06:07 +00:00
|
|
|
import { registerMailRoutes } from "./infrastructure/http/mail-configuration.routes";
|
2026-10-05 08:45:02 +00:00
|
|
|
import { registerMailboxRoutes } from "./infrastructure/http/mailbox.routes";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { registerPrinterConfigurationRoutes } from "./infrastructure/http/printer-configuration.routes";
|
2026-10-05 07:53:29 +00:00
|
|
|
import { registerWorkProfileRoutes } from "./infrastructure/http/work-profile.routes";
|
2026-10-03 13:19:20 +00:00
|
|
|
import {
|
|
|
|
|
AccessPersistenceMapper,
|
|
|
|
|
SequelizeAccessRepository,
|
|
|
|
|
migrateAccess,
|
|
|
|
|
} from "./infrastructure/persistence/access-persistence";
|
2026-10-03 10:36:03 +00:00
|
|
|
import { initializeCompanyModels } from "./infrastructure/persistence/company.model";
|
|
|
|
|
import { CompanyPersistenceMapper } from "./infrastructure/persistence/company-persistence.mapper";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { migrateFolderMappings } from "./infrastructure/persistence/folder-mapping-migration";
|
2026-10-04 21:06:07 +00:00
|
|
|
import { migrateMailConfigurations } from "./infrastructure/persistence/mail-configuration-migration";
|
2026-10-05 08:45:02 +00:00
|
|
|
import { migrateMailboxes } from "./infrastructure/persistence/mailbox-migration";
|
2026-10-03 10:36:03 +00:00
|
|
|
import { migrateCompanies } from "./infrastructure/persistence/migrate-companies";
|
2026-10-03 11:13:15 +00:00
|
|
|
import { migratePeople } from "./infrastructure/persistence/migrate-people";
|
|
|
|
|
import { initializePeopleModels } from "./infrastructure/persistence/people.model";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { migratePrinterConfigurations } from "./infrastructure/persistence/printer-configuration-migration";
|
2026-10-03 10:36:03 +00:00
|
|
|
import { SequelizeCompanyRepository } from "./infrastructure/persistence/sequelize-company.repository";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { SequelizeFolderMappingRepository } from "./infrastructure/persistence/sequelize-folder-mapping.repository";
|
2026-10-04 21:06:07 +00:00
|
|
|
import { SequelizeMailConfigurationRepository } from "./infrastructure/persistence/sequelize-mail-configuration.repository";
|
2026-10-05 08:45:02 +00:00
|
|
|
import { SequelizeMailboxRepository } from "./infrastructure/persistence/sequelize-mailbox.repository";
|
2026-10-05 15:01:32 +00:00
|
|
|
import { SequelizePrinterConfigurationRepository } from "./infrastructure/persistence/sequelize-printer-configuration.repository";
|
2026-10-05 07:53:29 +00:00
|
|
|
import { SequelizeWorkProfileRepository } from "./infrastructure/persistence/sequelize-work-profile.repository";
|
|
|
|
|
import { migrateWorkProfiles } from "./infrastructure/persistence/work-profile-migration";
|
2026-10-03 10:36:03 +00:00
|
|
|
|
2026-10-05 15:01:32 +00:00
|
|
|
export async function createCompanyModule(
|
|
|
|
|
database: Sequelize,
|
|
|
|
|
authenticate: RequestHandler,
|
|
|
|
|
legacyResourceWrites = false
|
|
|
|
|
) {
|
2026-10-03 10:36:03 +00:00
|
|
|
await migrateCompanies(database);
|
2026-10-03 11:13:15 +00:00
|
|
|
await migratePeople(database);
|
2026-10-03 10:36:03 +00:00
|
|
|
initializeCompanyModels(database);
|
2026-10-03 11:13:15 +00:00
|
|
|
initializePeopleModels(database);
|
2026-10-03 13:19:20 +00:00
|
|
|
const repository = new SequelizeCompanyRepository(database, new CompanyPersistenceMapper());
|
|
|
|
|
await migrateAccess(database);
|
|
|
|
|
const access = new AccessUseCases(
|
|
|
|
|
new SequelizeAccessRepository(database, repository, new AccessPersistenceMapper())
|
2026-10-03 10:36:03 +00:00
|
|
|
);
|
2026-10-03 13:19:20 +00:00
|
|
|
const useCases = new CompanyUseCases(repository, new CompanyInputMapper());
|
2026-10-03 10:36:03 +00:00
|
|
|
return {
|
2026-10-05 07:53:29 +00:00
|
|
|
initializeProfiles: async (inventory: IWorkProfileInventoryService) => {
|
|
|
|
|
await migrateWorkProfiles(database);
|
2026-10-05 10:02:04 +00:00
|
|
|
await migrateFolderMappings(database);
|
2026-10-05 15:01:32 +00:00
|
|
|
await migratePrinterConfigurations(database);
|
|
|
|
|
const printers = new PrinterConfigurationUseCases(
|
|
|
|
|
new SequelizePrinterConfigurationRepository(database, inventory)
|
|
|
|
|
);
|
|
|
|
|
const folders = new FolderMappingUseCases(
|
|
|
|
|
new SequelizeFolderMappingRepository(database, inventory)
|
|
|
|
|
);
|
2026-10-05 07:53:29 +00:00
|
|
|
const profiles = new WorkProfileUseCases(
|
|
|
|
|
new SequelizeWorkProfileRepository(database, inventory)
|
|
|
|
|
);
|
|
|
|
|
return {
|
2026-10-05 10:02:04 +00:00
|
|
|
register: (app: Parameters<typeof registerWorkProfileRoutes>[0]) => {
|
|
|
|
|
registerWorkProfileRoutes(app, profiles, authenticate);
|
|
|
|
|
registerFolderMappingRoutes(app, folders, authenticate);
|
2026-10-05 15:01:32 +00:00
|
|
|
registerPrinterConfigurationRoutes(app, printers, authenticate);
|
2026-10-05 10:02:04 +00:00
|
|
|
},
|
2026-10-05 07:53:29 +00:00
|
|
|
};
|
|
|
|
|
},
|
2026-10-04 21:06:07 +00:00
|
|
|
initializeMail: async (inventory: IMailInventoryService) => {
|
2026-10-05 08:45:02 +00:00
|
|
|
await migrateWorkProfiles(database);
|
|
|
|
|
await migrateMailboxes(database);
|
2026-10-04 21:06:07 +00:00
|
|
|
await migrateMailConfigurations(database);
|
2026-10-05 08:45:02 +00:00
|
|
|
const mailboxRepository = new SequelizeMailboxRepository(database);
|
|
|
|
|
const mailboxes = new MailboxUseCases(mailboxRepository);
|
2026-10-04 21:06:07 +00:00
|
|
|
const mail = new MailConfigurationUseCases(
|
2026-10-05 08:45:02 +00:00
|
|
|
new SequelizeMailConfigurationRepository(database, inventory, mailboxRepository)
|
2026-10-04 21:06:07 +00:00
|
|
|
);
|
|
|
|
|
return {
|
2026-10-05 08:45:02 +00:00
|
|
|
register: (app: Parameters<typeof registerMailRoutes>[0]) => {
|
|
|
|
|
registerMailRoutes(app, mail, authenticate);
|
2026-10-05 15:01:32 +00:00
|
|
|
registerMailboxRoutes(app, mailboxes, authenticate, legacyResourceWrites);
|
2026-10-05 08:45:02 +00:00
|
|
|
},
|
2026-10-04 21:06:07 +00:00
|
|
|
};
|
|
|
|
|
},
|
2026-10-03 13:19:20 +00:00
|
|
|
register: (app: Parameters<typeof registerCompanyRoutes>[0]) => {
|
|
|
|
|
registerCompanyRoutes(app, useCases, authenticate);
|
2026-10-05 15:01:32 +00:00
|
|
|
registerAccessRoutes(app, access, authenticate, legacyResourceWrites);
|
2026-10-03 13:19:20 +00:00
|
|
|
},
|
2026-10-03 10:36:03 +00:00
|
|
|
};
|
|
|
|
|
}
|