mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
refactor(server): let user-cleanup inject BudgetService and delete budget.bridge
This commit is contained in:
@@ -2,6 +2,9 @@ import { db } from '../../db/database';
|
||||
import { DatabaseService } from '../database/database.service';
|
||||
import { PermissionsService } from '../permissions/permissions.service';
|
||||
import { TripMembershipService } from '../trip-membership/trip-membership.service';
|
||||
import { BudgetService } from '../budget/budget.service';
|
||||
import { ExchangeRatesService } from '../budget/exchange-rates.service';
|
||||
import { RealtimeService } from '../realtime/realtime.service';
|
||||
import { AuthService } from './auth.service';
|
||||
import { TokenService } from '../tokens/token.service';
|
||||
import { MailerService } from '../notifications/mailer/mailer.service';
|
||||
@@ -21,7 +24,8 @@ import { EphemeralTokenService } from './ephemeral-token.service';
|
||||
* verifyJwtToken is login identity and deliberately stays on AuthService
|
||||
* (see token.service.ts), so the whole AuthService collaborator graph below
|
||||
* exists to serve that one call. WebauthnConfigService and UserCleanupService
|
||||
* are constructed only because AuthService takes them — nothing this file
|
||||
* (with the BudgetService it injects) are constructed only because AuthService
|
||||
* takes them — nothing this file
|
||||
* exports reaches either one. The pending-MFA and reset-throttle maps are
|
||||
* module-scoped in auth.service.ts, so this instance and the container
|
||||
* singleton share one copy.
|
||||
@@ -36,7 +40,7 @@ const auth = new AuthService(
|
||||
permissions,
|
||||
new TripMembershipService(dbs),
|
||||
new WebauthnConfigService(dbs),
|
||||
new UserCleanupService(dbs),
|
||||
new UserCleanupService(dbs, new BudgetService(dbs, permissions, new ExchangeRatesService(), new RealtimeService())),
|
||||
new MailerService(dbs),
|
||||
new EphemeralTokenService(),
|
||||
);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { AuthMcp } from './auth.mcp';
|
||||
import { UserCleanupService } from './user-cleanup.service';
|
||||
import { WebauthnConfigService } from './webauthn-config.service';
|
||||
import { AppConfigModule } from '../app-config/app-config.module';
|
||||
import { BudgetModule } from '../budget/budget.module';
|
||||
import { AuditModule } from '../audit/audit.module';
|
||||
import { MailerModule } from '../notifications/mailer/mailer.module';
|
||||
import { PermissionsModule } from '../permissions/permissions.module';
|
||||
@@ -31,7 +32,10 @@ import { EphemeralTokenModule } from './ephemeral-token.module';
|
||||
* AtlasModule is deliberately absent. getTravelStats was the only reason for it
|
||||
* and now belongs to AtlasService; the direction is reversed, so AtlasModule
|
||||
* imports AuthModule and atlas.mcp.ts can inject AuthService instead of routing
|
||||
* through auth.bridge. AuthService is
|
||||
* through auth.bridge. BudgetModule went the same way: it stopped importing
|
||||
* AuthModule when BudgetMcp's demo guard moved off AuthService, so this module
|
||||
* imports it and UserCleanupService injects BudgetService (which retired
|
||||
* budget.bridge). AuthService is
|
||||
* exported for the in-container consumers (the domain *.mcp.ts demo guards,
|
||||
* OidcService, PasskeyEnabledGuard); PasskeyService for AdminService's passkey
|
||||
* reset; UserCleanupService for the two account-deletion paths (AdminService)
|
||||
@@ -39,7 +43,7 @@ import { EphemeralTokenModule } from './ephemeral-token.module';
|
||||
* through auth.bridge.ts.
|
||||
*/
|
||||
@Module({
|
||||
imports: [EphemeralTokenModule, RateLimitModule, AuditModule, PermissionsModule, TripMembershipModule, MailerModule, AppConfigModule, TokensModule],
|
||||
imports: [EphemeralTokenModule, RateLimitModule, AuditModule, PermissionsModule, TripMembershipModule, MailerModule, AppConfigModule, TokensModule, BudgetModule],
|
||||
controllers: [AuthPublicController, AuthController, PasskeyController],
|
||||
providers: [AuthService, UserProfileService, RegistrationInvitesService, PasskeyService, UserCleanupService, WebauthnConfigService, AuthMcp],
|
||||
exports: [AuthService, RegistrationInvitesService, PasskeyService, UserCleanupService],
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import fs from 'node:fs';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DatabaseService } from '../database/database.service';
|
||||
// budget.bridge, not an injected BudgetService: BudgetModule imports AuthModule
|
||||
// (BudgetMcp's demo guard), so AuthModule importing BudgetModule back would
|
||||
// close a module cycle — and breaking it the other way would drag
|
||||
// BudgetController, BudgetMcp and its trips.bridge/MCP `_shared` chain into
|
||||
// every graph that imports AuthModule, including the single-domain e2e
|
||||
// TestingModules. Same documented in-container exception as atlas.mcp.ts.
|
||||
// The bridge instance runs its SQL over the shared db Proxy, and the re-split
|
||||
// keeps no state, so the second BudgetService is behaviourally identical.
|
||||
import { removeUserFromBudgetItems } from '../budget/budget.bridge';
|
||||
// Injected since BudgetModule dropped its AuthModule import (BudgetMcp's demo
|
||||
// guard reads RuntimeEnvService + the users table now), which un-closed the
|
||||
// AuthModule -> BudgetModule cycle that used to force budget.bridge here.
|
||||
import { BudgetService } from '../budget/budget.service';
|
||||
import { pluginsDataRoot } from '../plugins/paths';
|
||||
|
||||
/**
|
||||
@@ -26,7 +21,10 @@ import { pluginsDataRoot } from '../plugins/paths';
|
||||
*/
|
||||
@Injectable()
|
||||
export class UserCleanupService {
|
||||
constructor(private readonly db: DatabaseService) {}
|
||||
constructor(
|
||||
private readonly db: DatabaseService,
|
||||
private readonly budget: BudgetService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Erase a user's PLUGIN-held data on account deletion. Two parts:
|
||||
@@ -68,7 +66,7 @@ export class UserCleanupService {
|
||||
private cleanupUserReferences(userId: number): void {
|
||||
this.db.run('UPDATE trip_members SET invited_by = NULL WHERE invited_by = ?', userId);
|
||||
this.db.run('UPDATE budget_items SET paid_by_user_id = NULL WHERE paid_by_user_id = ?', userId);
|
||||
removeUserFromBudgetItems(userId);
|
||||
this.budget.removeUserFromBudgetItems(userId);
|
||||
this.db.run('DELETE FROM share_tokens WHERE created_by = ?', userId);
|
||||
this.db.run('DELETE FROM journey_share_tokens WHERE created_by = ?', userId);
|
||||
// Owned journeys cascade-delete their entries/contributors/share_tokens/photos via journey_id FKs
|
||||
|
||||
Reference in New Issue
Block a user