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
@@ -15,15 +15,13 @@ import type { EntityManager } from '@mikro-orm/core';
* all — so `connection.execute()` (the last tier in the program's query-API
* order) is the correct tool, not a shortcut around it.
*
* Constructed directly (`new MaintenanceRepository(em)`), never through Nest
* DI: its only two callers — `backup.impl.ts#createBackup` and
* `demo/demo-reset.ts` (`resetDemoUser`/`saveBaseline`) — are plain function
* modules, not Nest providers, and obtain the `EntityManager` via
* `RequestContext.getEntityManager()` (the same static accessor MikroORM's
* own per-request middleware and `CronRegistrarService`'s `wrappedTick`
* populate) rather than constructor injection. No module registers this
* class as a provider — nothing today asks Nest's DI container to resolve
* it.
* Provided through Nest DI by `MaintenanceModule` (`nest/database/`), a
* factory over the context-resolving global `EntityManager`; the readiness
* probe and `UserCleanupService` inject it. `backup.impl.ts` and
* `demo/demo-reset.ts` still build one over the request's EntityManager until
* they move behind an injected provider of their own. The class stays free of
* Nest decorators like every other file under `db/`, so a test can still
* build one over its own `EntityManager`.
*/
export class MaintenanceRepository {
constructor(private readonly em: EntityManager) {}