refactor(server): provide MaintenanceRepository through DI

MaintenanceRepository was built with new over an injected EntityManager
in the readiness probe and in UserCleanupService, outside the container.
MaintenanceModule now provides it, as a factory over the same
context-resolving EntityManager Nest injects everywhere, and both inject
it. The class itself stays free of Nest decorators, like the rest of
src/db, so tests keep building one over their own EntityManager.

No behaviour changes: the probe still pings and the erasure still runs
inside the account deletion's transaction.
This commit is contained in:
Maurice
2026-10-08 15:23:20 +02:00
parent 0a4c6fbace
commit 8ede0dab9e
19 changed files with 81 additions and 41 deletions
@@ -0,0 +1,25 @@
import { Module } from '@nestjs/common';
import { EntityManager } from '@mikro-orm/core';
import { MaintenanceRepository } from '../../db/repositories/MaintenanceRepository';
/**
* Provides `MaintenanceRepository`, the home of the few whole-database
* statements no entity can express (the readiness ping, the WAL checkpoint,
* `VACUUM INTO`, the plugin-table erasure).
*
* A factory over the context-resolving global `EntityManager`, the same one
* Nest injects into every service, so the repository resolves the request or
* transaction fork that is active when a method runs. The class itself stays
* free of Nest, like every other file under `db/`.
*/
@Module({
providers: [
{
provide: MaintenanceRepository,
useFactory: (em: EntityManager) => new MaintenanceRepository(em),
inject: [EntityManager],
},
],
exports: [MaintenanceRepository],
})
export class MaintenanceModule {}