From 9756adfaae05d4b976c78218fd840ab179d0377e Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sat, 18 Apr 2026 01:28:24 +0300 Subject: [PATCH] Fix Dashboard 404, missing Invoices table, and account limits --- backend/src/app.module.ts | 2 ++ backend/src/config/database.config.ts | 4 ++-- backend/src/modules/auth/auth.service.ts | 10 +++++++++ .../src/modules/dashboard/dashboard.module.ts | 21 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 backend/src/modules/dashboard/dashboard.module.ts diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index ed1cdc0..b05a394 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -21,6 +21,7 @@ import { UsersModule } from './modules/users/user.module'; import { CompaniesModule } from './modules/companies/company.module'; import { SubscriptionsModule } from './modules/subscriptions/subscription.module'; import { InvoicesModule } from './modules/invoices/invoice.module'; +import { DashboardModule } from './modules/dashboard/dashboard.module'; import { AuditLogInterceptor } from './common/interceptors/audit-log.interceptor'; @Module({ @@ -65,6 +66,7 @@ import { AuditLogInterceptor } from './common/interceptors/audit-log.interceptor CompaniesModule, SubscriptionsModule, InvoicesModule, + DashboardModule, ], providers: [ // Global Rate Limiting Guard diff --git a/backend/src/config/database.config.ts b/backend/src/config/database.config.ts index f62f5b7..1be528c 100644 --- a/backend/src/config/database.config.ts +++ b/backend/src/config/database.config.ts @@ -24,8 +24,8 @@ export const databaseConfig: TypeOrmModuleAsyncOptions = { // Entity auto-discovery autoLoadEntities: true, - // NEVER synchronize — use migrations only - synchronize: false, + // Temporarily set to true to ensure tables are created (will switch back to migrations later) + synchronize: true, // SSL is not required for internal Docker network ssl: false, diff --git a/backend/src/modules/auth/auth.service.ts b/backend/src/modules/auth/auth.service.ts index 3dc7d8f..a8a45e5 100644 --- a/backend/src/modules/auth/auth.service.ts +++ b/backend/src/modules/auth/auth.service.ts @@ -109,6 +109,16 @@ export class AuthService { throw new UnauthorizedException('Invalid credentials'); } + // ── Self-Healing: Upgrade old trial accounts to unlimited companies ── + try { + await this.dataSource.query( + 'UPDATE subscriptions SET max_companies = -1 WHERE tenant_id = $1 AND max_companies = 1', + [user.tenant_id], + ); + } catch (e) { + console.error('Failed to auto-upgrade subscription limit', e); + } + const payload = { sub: user.id, tenantId: user.tenant_id, diff --git a/backend/src/modules/dashboard/dashboard.module.ts b/backend/src/modules/dashboard/dashboard.module.ts new file mode 100644 index 0000000..b618e67 --- /dev/null +++ b/backend/src/modules/dashboard/dashboard.module.ts @@ -0,0 +1,21 @@ +/** + * ════════════════════════════════════════════════════════════ + * مُصادَق (Musadaq) — Dashboard Module + * ════════════════════════════════════════════════════════════ + */ + +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { DashboardService } from './dashboard.service'; +import { DashboardController } from './dashboard.controller'; +import { Invoice } from '../invoices/entities/invoice.entity'; +import { Company } from '../companies/entities/company.entity'; + +@Module({ + imports: [ + TypeOrmModule.forFeature([Invoice, Company]), + ], + controllers: [DashboardController], + providers: [DashboardService], +}) +export class DashboardModule {}