diff --git a/src/app/core/services/auth.service.ts b/src/app/core/services/auth.service.ts index 1d657d2..0385a30 100644 --- a/src/app/core/services/auth.service.ts +++ b/src/app/core/services/auth.service.ts @@ -61,14 +61,14 @@ export class AuthService { private readonly tokenKey = 'access_token'; private readonly refreshTokenKey = 'refresh_token'; - - private readonly dashboardAccessService = inject(DashboardAccessService); - private readonly transactionAccessService = inject(TransactionAccessService); private authState$ = new BehaviorSubject(this.isAuthenticated()); private userProfile$ = new BehaviorSubject(null); private initialized$ = new BehaviorSubject(false); + private readonly dashboardAccessService = inject(DashboardAccessService); + private readonly transactionAccessService = inject(TransactionAccessService); + // === INITIALISATION DE L'APPLICATION === /** diff --git a/src/app/layouts/components/sidenav/components/user-profile/user-profile.component.ts b/src/app/layouts/components/sidenav/components/user-profile/user-profile.component.ts index 01467b2..296ca02 100644 --- a/src/app/layouts/components/sidenav/components/user-profile/user-profile.component.ts +++ b/src/app/layouts/components/sidenav/components/user-profile/user-profile.component.ts @@ -128,7 +128,6 @@ export class UserProfileComponent implements OnInit, OnDestroy { * Charge le profil utilisateur explicitement */ loadUserProfile(): void { - console.log('🚀 Loading user profile...'); this.isLoading = true; this.hasError = false; this.cdr.detectChanges(); @@ -137,7 +136,6 @@ export class UserProfileComponent implements OnInit, OnDestroy { .pipe(takeUntil(this.destroy$)) .subscribe({ next: (profile) => { - console.log('✅ Profile loaded successfully:', profile.username); // Note: le profil sera automatiquement mis à jour via la subscription getUserProfile() this.isLoading = false; this.cdr.detectChanges(); @@ -240,13 +238,7 @@ export class UserProfileComponent implements OnInit, OnDestroy { * Obtient l'URL de l'avatar de l'utilisateur */ getUserAvatar(): string { - if (!this.user) { - return 'assets/images/users/user-default.jpg'; - } - - // Vous pouvez implémenter une logique pour générer un avatar personnalisé - // ou utiliser une image par défaut basée sur l'email/nom - return `assets/images/users/user-${(this.user.id?.charCodeAt(0) % 5) + 1}.jpg`; + return `assets/images/users/user-2.jpg`; } /** @@ -254,7 +246,7 @@ export class UserProfileComponent implements OnInit, OnDestroy { */ onAvatarError(event: Event): void { const img = event.target as HTMLImageElement; - img.src = 'assets/images/users/user-default.jpg'; - img.onerror = null; // Éviter les boucles infinies + img.src = 'assets/images/users/user-2.jpg'; + img.onerror = null; } } \ No newline at end of file diff --git a/src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.html b/src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.html deleted file mode 100644 index e36daf8..0000000 --- a/src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.html +++ /dev/null @@ -1,768 +0,0 @@ -
- -
-
-
-

- - Dashboard FinTech Reporting - - - Merchant {{ merchantId }} - - - - Hub Admin - -

-

- - {{ currentRoleLabel }} - {{ getCurrentMerchantName() }} -

-
-
- -
- - - - - -
- - -
-
- -
- - - - - -
- - -
- - {{ getCurrentMerchantName() }} -
-
-
- - - -
-
-
- - -
-
- -
-
- - {{ currentRoleLabel }} -
-
- - -
-
- - {{ getCurrentMerchantName() }} -
-
- -
-
- - Mis à jour: {{ lastUpdated | date:'HH:mm:ss' }} -
-
- - -
-
- - Services: {{ stats.onlineServices }}/{{ stats.totalServices }} en ligne -
-
- - -
-
- - Merchant ID: {{ merchantId }} -
-
- - -
-
- - Merchant ID: {{ merchantId }} -
-
-
-
- - -
-
- -
- Permissions insuffisantes -
Vous n'avez pas les permissions nécessaires pour voir les données.
-
-
-
- - -
-
- -
- {{ syncResponse.message }} -
Synchronisée à {{ formatDate(syncResponse.timestamp) }}
-
- -
-
- - -
-
- -
-
-
-
-
-
Transactions
-

{{ formatNumber(getPaymentStats().daily.transactions) }}

- Journalier -
-
- -
-
-
- {{ formatCurrency(getPaymentStats().daily.revenue) }} - - - {{ getPaymentStats().daily.successRate | number:'1.0-0' }}% - -
-
-
-
- - -
-
-
-
-
-
Transactions
-

{{ formatNumber(getPaymentStats().weekly.transactions) }}

- Hebdomadaire -
-
- -
-
-
- {{ formatCurrency(getPaymentStats().weekly.revenue) }} - - - {{ getPaymentStats().weekly.successRate | number:'1.0-0' }}% - -
-
-
-
- - -
-
-
-
-
-
Transactions
-

{{ formatNumber(getPaymentStats().monthly.transactions) }}

- Mensuel -
-
- -
-
-
- {{ formatCurrency(getPaymentStats().monthly.revenue) }} - - - {{ getPaymentStats().monthly.successRate | number:'1.0-0' }}% - -
-
-
-
- - -
-
-
-
-
-
Revenue {{ currentYear }}
-

{{ formatCurrency(stats.yearlyRevenue) }}

- Annuel -
-
- -
-
-
- {{ formatNumber(stats.yearlyTransactions) }} transactions - - - {{ currentYear }} - -
-
-
-
- - -
-
-
-
-
-
Abonnements
-

{{ formatNumber(getSubscriptionStats().active) }}

- Actifs -
-
- -
-
-
- Total: {{ formatNumber(getSubscriptionStats().total) }} - - - +{{ getSubscriptionStats().newToday }} - -
-
-
-
- - -
-
-
-
-
-
Taux de succès
-

{{ stats.successRate | number:'1.1-1' }}%

- Global -
-
- -
-
-
- {{ getPerformanceLabel(stats.successRate) }} - - - {{ stats.avgSuccessRate | number:'1.0-0' }}% cible - -
-
-
-
-
-
- - -
-
- -
-
-
-
-
-
- - {{ getChartTitle(dataSelection.metric) }} - - - Merchant {{ merchantId }} - - - - Données globales - -
-

Visualisation en temps réel

-
-
- - - - -
- -
- - -
-
-
-
-
-
-

Chargement du graphique...

-
-
- -

Aucune donnée disponible

- -
-
- -
-
-
-
- - -
-
- -
-
-
-
-
- - Comparaison Hebdo/Mens -
- Dernières 8 périodes -
-
-
-
- - Données de comparaison indisponibles -
-
- -
-
-
-
- - -
-
-
-
-
- - Performance -
- -
-
-
-
-
- -
-

- {{ stats.successRate | number:'1.0-0' }}% -

- Taux de succès -
-
-
- -
-
-
-
- {{ formatNumber(getCurrentTransactionData()?.items?.[0]?.successCount || 0) }} -
- Réussies -
-
-
-
-
- {{ formatNumber(getCurrentTransactionData()?.items?.[0]?.failedCount || 0) }} -
- Échouées -
-
-
-
-
- {{ formatNumber(getCurrentTransactionData()?.items?.[0]?.pendingCount || 0) }} -
- En attente -
-
-
-
-
-
-
-
-
-
- - -
-
-
-
-
-
- - Santé des APIs DCB -
-

Statut en temps réel des services backend

-
-
-
-
- - {{ overallHealth.message }} -
-
- -
-
-
-
-
-
-
-
-
-
-
{{ service.service }}
- {{ service.url }} -
-
- - {{ service.status }} - - - {{ service.statusCode }} - -
-
-
-
- - - {{ formatTimeAgo(service.checkedAt) }} - -
-
- - {{ service.responseTime }} - -
-
-
- - - {{ service.error }} - -
-
-
-
-
-
- - - Vérification automatique toutes les 5 minutes - -
-
-
-
- - -
-
- -
-
-
-
-
-
- - Transactions récentes - - {{ getCurrentMerchantName() }} - -
-

Dernières 24 heures

-
-
- -
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - -
PériodeMontantTransactionsSuccès
-
{{ item.period }}
- {{ isViewingGlobal() ? 'Tous merchants' : 'Merchant ' + merchantId }} -
-
{{ formatCurrency(item.totalAmount) }}
-
-
{{ formatNumber(item.count) }}
-
- - {{ (item.count > 0 ? (item.successCount / item.count) * 100 : 0) | number:'1.1-1' }}% - -
- -

Aucune transaction disponible

-
-
-
- -
-
- - -
-
-
-
-
-
- - Alertes système -
-

Notifications en temps réel

-
-
- - {{ alerts.length }} - -
-
-
-
-
-
-
-
- - - - -
-
-
-
{{ alert.title }}
- {{ formatTimeAgo(alert.timestamp) }} -
-

{{ alert.description }}

-
-
-
-
- -

Aucune alerte active

- Tous les systèmes fonctionnent normalement -
-
-
- -
-
-
-
- - - -
\ No newline at end of file diff --git a/src/app/modules/dcb-dashboard/dcb-dashboard.html b/src/app/modules/dcb-dashboard/dcb-dashboard.html deleted file mode 100644 index cecea17..0000000 --- a/src/app/modules/dcb-dashboard/dcb-dashboard.html +++ /dev/null @@ -1,13 +0,0 @@ -
- - -
-
- -
-
-
\ No newline at end of file diff --git a/src/app/modules/dcb-dashboard/dcb-dashboard.spec.ts b/src/app/modules/dcb-dashboard/dcb-dashboard.spec.ts deleted file mode 100644 index ba834c8..0000000 --- a/src/app/modules/dcb-dashboard/dcb-dashboard.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing' - -import { DcbDashboard } from './dcb-dashboard' - -describe('Dashboard', () => { - let component: DcbDashboard - let fixture: ComponentFixture - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [DcbDashboard], - }).compileComponents() - - fixture = TestBed.createComponent(DcbDashboard) - component = fixture.componentInstance - fixture.detectChanges() - }) - - it('should create', () => { - expect(component).toBeTruthy() - }) -}) diff --git a/src/app/modules/dcb-dashboard/dcb-dashboard.ts b/src/app/modules/dcb-dashboard/dcb-dashboard.ts deleted file mode 100644 index 6a75cb4..0000000 --- a/src/app/modules/dcb-dashboard/dcb-dashboard.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { PageTitle } from '@app/components/page-title/page-title'; -import { DcbReportingDashboard } from './components/dcb-reporting-dashboard'; - -@Component({ - selector: 'app-dcb-dashboard', - imports: [ - CommonModule, - PageTitle, - DcbReportingDashboard, - ], - templateUrl: './dcb-dashboard.html', -}) -export class DcbDashboard {} \ No newline at end of file diff --git a/src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.css b/src/app/modules/dcb-dashboard/dcb-reporting-dashboard.css similarity index 100% rename from src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.css rename to src/app/modules/dcb-dashboard/dcb-reporting-dashboard.css diff --git a/src/app/modules/dcb-dashboard/dcb-reporting-dashboard.html b/src/app/modules/dcb-dashboard/dcb-reporting-dashboard.html new file mode 100644 index 0000000..e1fcd11 --- /dev/null +++ b/src/app/modules/dcb-dashboard/dcb-reporting-dashboard.html @@ -0,0 +1,785 @@ +
+ + +
+
+
+ +
+
+
+

+ + Dashboard FinTech Reporting + + +
+ Merchant ID: {{ merchantId }} +
+
+ Aucun merchant sélectionné +
+
+ + + Hub Admin + +

+

+ + {{ currentRoleLabel }} - {{ getCurrentMerchantName() }} +

+
+
+ +
+ + + + + +
+ + +
+
+ +
+ + + + + +
+ + +
+ + {{ getCurrentMerchantName() }} +
+
+
+ + + +
+
+
+ + +
+
+ +
+
+ + {{ currentRoleLabel }} +
+
+ + +
+
+ + {{ getCurrentMerchantName() }} +
+
+ +
+
+ + Mis à jour: {{ lastUpdated | date:'HH:mm:ss' }} +
+
+ + +
+
+ + Services: {{ stats.onlineServices }}/{{ stats.totalServices }} en ligne +
+
+ + +
+
+ + Merchant ID: {{ merchantId }} +
+
+ + +
+
+ + Merchant ID: {{ merchantId }} +
+
+
+
+ + +
+
+ +
+ Permissions insuffisantes +
Vous n'avez pas les permissions nécessaires pour voir les données.
+
+
+
+ + +
+
+ +
+ {{ syncResponse.message }} +
Synchronisée à {{ formatDate(syncResponse.timestamp) }}
+
+ +
+
+ + +
+
+ +
+
+
+
+
+
Transactions
+

{{ formatNumber(getPaymentStats().daily.transactions) }}

+ Journalier +
+
+ +
+
+
+ {{ formatCurrency(getPaymentStats().daily.revenue) }} + + + {{ getPaymentStats().daily.successRate | number:'1.0-0' }}% + +
+
+
+
+ + +
+
+
+
+
+
Transactions
+

{{ formatNumber(getPaymentStats().weekly.transactions) }}

+ Hebdomadaire +
+
+ +
+
+
+ {{ formatCurrency(getPaymentStats().weekly.revenue) }} + + + {{ getPaymentStats().weekly.successRate | number:'1.0-0' }}% + +
+
+
+
+ + +
+
+
+
+
+
Transactions
+

{{ formatNumber(getPaymentStats().monthly.transactions) }}

+ Mensuel +
+
+ +
+
+
+ {{ formatCurrency(getPaymentStats().monthly.revenue) }} + + + {{ getPaymentStats().monthly.successRate | number:'1.0-0' }}% + +
+
+
+
+ + +
+
+
+
+
+
Revenue {{ currentYear }}
+

{{ formatCurrency(stats.yearlyRevenue) }}

+ Annuel +
+
+ +
+
+
+ {{ formatNumber(stats.yearlyTransactions) }} transactions + + + {{ currentYear }} + +
+
+
+
+ + +
+
+
+
+
+
Abonnements
+

{{ formatNumber(getSubscriptionStats().active) }}

+ Actifs +
+
+ +
+
+
+ Total: {{ formatNumber(getSubscriptionStats().total) }} + + + +{{ getSubscriptionStats().newToday }} + +
+
+
+
+ + +
+
+
+
+
+
Taux de succès
+

{{ stats.successRate | number:'1.1-1' }}%

+ Global +
+
+ +
+
+
+ {{ getPerformanceLabel(stats.successRate) }} + + + {{ stats.avgSuccessRate | number:'1.0-0' }}% cible + +
+
+
+
+
+
+ + +
+
+ +
+
+
+
+
+
+ + {{ getChartTitle(dataSelection.metric) }} + + + Merchant {{ merchantId }} + + + + Données globales + +
+

Visualisation en temps réel

+
+
+ + + + +
+ +
+ + +
+
+
+
+
+
+

Chargement du graphique...

+
+
+ +

Aucune donnée disponible

+ +
+
+ +
+
+
+
+ + +
+
+ +
+
+
+
+
+ + Comparaison Hebdo/Mens +
+ Dernières 8 périodes +
+
+
+
+ + Données de comparaison indisponibles +
+
+ +
+
+
+
+ + +
+
+
+
+
+ + Performance +
+ +
+
+
+
+
+ +
+

+ {{ stats.successRate | number:'1.0-0' }}% +

+ Taux de succès +
+
+
+ +
+
+
+
+ {{ formatNumber(getCurrentTransactionData()?.items?.[0]?.successCount || 0) }} +
+ Réussies +
+
+
+
+
+ {{ formatNumber(getCurrentTransactionData()?.items?.[0]?.failedCount || 0) }} +
+ Échouées +
+
+
+
+
+ {{ formatNumber(getCurrentTransactionData()?.items?.[0]?.pendingCount || 0) }} +
+ En attente +
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+ + Santé des APIs DCB +
+

Statut en temps réel des services backend

+
+
+
+
+ + {{ overallHealth.message }} +
+
+ +
+
+
+
+
+
+
+
+
+
+
{{ service.service }}
+ {{ service.url }} +
+
+ + {{ service.status }} + + + {{ service.statusCode }} + +
+
+
+
+ + + {{ formatTimeAgo(service.checkedAt) }} + +
+
+ + {{ service.responseTime }} + +
+
+
+ + + {{ service.error }} + +
+
+
+
+
+
+ + + Vérification automatique toutes les 5 minutes + +
+
+
+
+ + +
+
+ +
+
+
+
+
+
+ + Transactions récentes + + {{ getCurrentMerchantName() }} + +
+

Dernières 24 heures

+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
PériodeMontantTransactionsSuccès
+
{{ item.period }}
+ {{ isViewingGlobal() ? 'Tous merchants' : 'Merchant ' + merchantId }} +
+
{{ formatCurrency(item.totalAmount) }}
+
+
{{ formatNumber(item.count) }}
+
+ + {{ (item.count > 0 ? (item.successCount / item.count) * 100 : 0) | number:'1.1-1' }}% + +
+ +

Aucune transaction disponible

+
+
+
+ +
+
+ + +
+
+
+
+
+
+ + Alertes système +
+

Notifications en temps réel

+
+
+ + {{ alerts.length }} + +
+
+
+
+
+
+
+
+ + + + +
+
+
+
{{ alert.title }}
+ {{ formatTimeAgo(alert.timestamp) }} +
+

{{ alert.description }}

+
+
+
+
+ +

Aucune alerte active

+ Tous les systèmes fonctionnent normalement +
+
+
+ +
+
+
+
+ + + +
+
+
+
\ No newline at end of file diff --git a/src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.ts b/src/app/modules/dcb-dashboard/dcb-reporting-dashboard.ts similarity index 94% rename from src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.ts rename to src/app/modules/dcb-dashboard/dcb-reporting-dashboard.ts index e76ecd1..0c93e5a 100644 --- a/src/app/modules/dcb-dashboard/components/dcb-reporting-dashboard.ts +++ b/src/app/modules/dcb-dashboard/dcb-reporting-dashboard.ts @@ -34,10 +34,11 @@ import { HealthCheckStatus, ChartDataNormalized, ReportPeriod -} from '../models/dcb-reporting.models'; -import { ReportService } from '../services/dcb-reporting.service'; -import { DashboardAccess, AllowedMerchant, DashboardAccessService } from '../services/dashboard-access.service'; +} from './models/dcb-reporting.models'; +import { ReportService } from './services/dcb-reporting.service'; +import { DashboardAccess, AllowedMerchant, DashboardAccessService } from './services/dashboard-access.service'; import { AuthService } from '@core/services/auth.service'; +import { PageTitle } from '@app/components/page-title/page-title'; // ============ TYPES ET INTERFACES ============ @@ -132,7 +133,12 @@ interface SubscriptionStats { templateUrl: './dcb-reporting-dashboard.html', styleUrls: ['./dcb-reporting-dashboard.css'], standalone: true, - imports: [CommonModule, FormsModule, NgIconComponent, NgbDropdownModule], + imports: [ + CommonModule, + FormsModule, + NgIconComponent, + NgbDropdownModule, + PageTitle], providers: [ provideIcons({ lucideActivity, lucideAlertCircle, lucideCheckCircle2, lucideRefreshCw, @@ -197,7 +203,7 @@ export class DcbReportingDashboard implements OnInit, OnDestroy, AfterViewInit { ]; // ============ PARAMÈTRES ============ - merchantId: number | null = null; + merchantId: number | undefined = undefined; startDate: string = new Date().toISOString().split('T')[0]; endDate: string = new Date().toISOString().split('T')[0]; currentYear = new Date().getFullYear(); @@ -307,7 +313,7 @@ export class DcbReportingDashboard implements OnInit, OnDestroy, AfterViewInit { this.initializeAccess(); this.loadAllowedMerchants(); this.initializeDashboard(); - + if (this.accessService.shouldShowSystemHealth()) { setInterval(() => { this.checkSystemHealth(); @@ -315,43 +321,59 @@ export class DcbReportingDashboard implements OnInit, OnDestroy, AfterViewInit { } } + // ============ INITIALISATION ============ + private initializeAccess(): void { this.access = this.accessService.getDashboardAccess(); this.currentRoleLabel = this.access.roleLabel; this.currentRoleIcon = this.access.roleIcon; - - const merchantPartnerId = this.access.merchantId; - + + // Récupérer le merchant ID du service d'accès + const merchantPartnerId = this.getCurrentMerchantPartnerId(); + if (this.access.isMerchantUser) { - + // Pour les merchant users, vérifier que l'ID est valide if (merchantPartnerId) { - // Utiliser le merchantId du cache directement s'il existe - if (this.access.merchantId) { - this.merchantId = this.access.merchantId; - } else { - // Sinon, essayer de le récupérer - const idNum = Number(merchantPartnerId); - this.merchantId = isNaN(idNum) ? null : idNum; - } + this.merchantId = Number(merchantPartnerId); + this.accessService.setSelectedMerchantId(this.merchantId); + this.isViewingGlobalData = false; - if (this.merchantId) { - this.accessService.setSelectedMerchantId(this.merchantId); - this.isViewingGlobalData = false; - } + console.log(`Merchant User: ID = ${this.merchantId}`); + } else { + console.error('Merchant ID invalide pour Merchant User:', merchantPartnerId); + this.addAlert('danger', 'Erreur de configuration', + 'Impossible de déterminer le merchant ID', 'Maintenant'); + this.isViewingGlobalData = false; } } else if (this.access.isHubUser) { + // Pour les hub users, vérifier si un merchant est sélectionné const selectedMerchantId = this.accessService.getSelectedMerchantId(); - if (selectedMerchantId) { + + if (selectedMerchantId && selectedMerchantId > 0) { this.merchantId = selectedMerchantId; this.isViewingGlobalData = false; + console.log(`Hub User: Merchant sélectionné = ${this.merchantId}`); } else { this.isViewingGlobalData = true; + this.merchantId = undefined; + console.log('Hub User: Mode global (aucun merchant sélectionné)'); } } + + // Mettre à jour la sélection de données + this.dataSelection.merchantPartnerId = this.isViewingGlobalData ? + undefined : this.merchantId; + } + + isValidMerchantId(id: any): boolean { + if (id === null || id === undefined) { + return false; + } + + const numId = Number(id); + return !isNaN(numId) && Number.isInteger(numId) && numId > 0; } - // ============ INITIALISATION ============ - private loadAllowedMerchants(): void { this.subscriptions.push( this.accessService.getAvailableMerchants().subscribe({ @@ -368,7 +390,6 @@ export class DcbReportingDashboard implements OnInit, OnDestroy, AfterViewInit { } private initializeDashboard(): void { - console.log(`Dashboard initialisé pour: ${this.currentRoleLabel} (${this.access.isHubUser ? 'Hub User' : 'Merchant User'})`); if (this.access.isHubUser) { if (this.isViewingGlobalData) { @@ -420,13 +441,28 @@ export class DcbReportingDashboard implements OnInit, OnDestroy, AfterViewInit { ); } - private loadMerchantData(merchantId: number | null): void { + private loadMerchantData(merchantId: number | undefined): void { console.log('Chargement des données pour merchant:', merchantId); - if (!merchantId) { - console.error('Merchant ID invalide:', merchantId); - this.addAlert('danger', 'Erreur', 'Merchant ID invalide', 'Maintenant'); - return; + // Vérification plus robuste + if (!merchantId || merchantId <= 0 || isNaN(merchantId)) { + console.error('Merchant ID invalide ou manquant:', merchantId); + this.addAlert('warning', 'Merchant non spécifié', + 'Veuillez sélectionner un merchant valide', 'Maintenant'); + + // Pour les merchant users, essayer de récupérer l'ID depuis le cache + if (this.access.isMerchantUser) { + const cachedId = this.accessService.getSelectedMerchantId(); + if (cachedId && cachedId > 0) { + merchantId = cachedId; + this.merchantId = cachedId; + console.log(`Utilisation du merchant ID du cache: ${merchantId}`); + } else { + return; + } + } else { + return; + } } this.loading.merchantData = true; @@ -452,7 +488,8 @@ export class DcbReportingDashboard implements OnInit, OnDestroy, AfterViewInit { error: (err) => { console.error(`Erreur lors du chargement des données du merchant ${merchantId}:`, err); this.loading.merchantData = false; - this.addAlert('danger', 'Erreur de chargement', `Impossible de charger les données du merchant ${merchantId}`, 'Maintenant'); + this.addAlert('danger', 'Erreur de chargement', + `Impossible de charger les données du merchant ${merchantId}`, 'Maintenant'); this.cdr.detectChanges(); } }) diff --git a/src/app/modules/dcb-dashboard/services/dashboard-access.service.ts b/src/app/modules/dcb-dashboard/services/dashboard-access.service.ts index 5e7127a..8ef0165 100644 --- a/src/app/modules/dcb-dashboard/services/dashboard-access.service.ts +++ b/src/app/modules/dcb-dashboard/services/dashboard-access.service.ts @@ -69,17 +69,27 @@ export class DashboardAccessService { /** * Obtient le merchant ID pour un merchant user */ - private getMerchantIdForUser(): number | undefined { + private getMerchantIdForUser(): number | undefined { // Récupérer le merchant ID de l'utilisateur courant const authService = this.injector.get(AuthService); const merchantPartnerId = authService.getCurrentMerchantPartnerId(); - if (!merchantPartnerId) return undefined; + // Vérifier si la valeur existe et est numérique + if (!merchantPartnerId) { + console.warn('Aucun merchant ID trouvé pour l\'utilisateur'); + return undefined; + } - const merchantId = parseInt(merchantPartnerId, 10); - - return isNaN(merchantId) ? undefined : merchantId; + // Convertir en nombre en gérant les erreurs + const merchantId = Number(merchantPartnerId); + + if (isNaN(merchantId) || !Number.isInteger(merchantId)) { + console.error(`Merchant ID invalide: ${merchantPartnerId}`); + return undefined; + } + + return merchantId; } /** diff --git a/src/app/modules/modules.routes.ts b/src/app/modules/modules.routes.ts index 27d1c10..c902e02 100644 --- a/src/app/modules/modules.routes.ts +++ b/src/app/modules/modules.routes.ts @@ -6,7 +6,7 @@ import { HubUsersManagement } from '@modules/hub-users-management/hub-users'; import { MerchantUsersManagement } from '@modules/hub-users-management/merchant-users'; // Composants principaux -import { DcbDashboard } from '@modules/dcb-dashboard/dcb-dashboard'; +import { DcbReportingDashboard } from '@modules/dcb-dashboard/dcb-reporting-dashboard'; import { Team } from '@modules/team/team'; import { Transactions } from '@modules/transactions/transactions'; import { OperatorsConfig } from '@modules/operators/config/config'; @@ -32,7 +32,7 @@ const routes: Routes = [ { path: 'dcb-dashboard', canActivate: [authGuard, roleGuard], - component: DcbDashboard, + component: DcbReportingDashboard, data: { title: 'Dashboard DCB', module: 'dcb-dashboard'