| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import { Injectable, inject } from '@angular/core';
- import { ApiClientService } from './api-client.service';
- import type { GroupChatDto } from './qiwe-api.service';
- import type { StoreDto } from './qiwe-api.service';
- export interface DashboardStatsDto {
- totalGroups: number;
- totalMembers: number;
- activeGroupRate: number;
- avgHealthScore: number;
- complianceRate: number;
- riskEventCount: number;
- pendingWorkOrders: number;
- intentLeadCount: number;
- conversionRate: number;
- }
- export interface DashboardScopeGroupOption {
- roomId: string;
- roomName: string;
- district: string;
- }
- export interface ResolvedScopeDto {
- level: 'global' | 'region' | 'store' | 'city' | 'district' | 'group';
- storeId?: string;
- storeIds?: string[];
- regionCode?: string;
- storeName?: string;
- district?: string;
- roomId?: string;
- label?: string;
- }
- export interface DashboardOverviewDto {
- stats: DashboardStatsDto;
- activityDistribution: { high: number; medium: number; low: number; inactive: number };
- lifecycleDistribution: Array<{ phase: string; label: string; count: number }>;
- healthGradeDistribution: Record<string, number>;
- storeComparison: Array<{ storeName: string; groupCount: number }>;
- districtComparison: Array<{ district: string; groupCount: number }>;
- topGroups: GroupChatDto[];
- recentRiskEvents: [];
- stores: StoreDto[];
- districts: string[];
- groupsByDistrict: Record<string, DashboardScopeGroupOption[]>;
- scope: ResolvedScopeDto;
- viewer: { id: string; name: string; role: string; storeId: string; storeName: string; regionCode?: string };
- }
- export interface DashboardScopeQuery {
- scopeLevel?: 'global' | 'region' | 'store' | 'city' | 'district' | 'group';
- storeId?: string;
- district?: string;
- roomId?: string;
- }
- @Injectable({ providedIn: 'root' })
- export class DashboardApiService {
- private readonly api = inject(ApiClientService);
- getOverview(scope: DashboardScopeQuery = {}) {
- const params = new URLSearchParams();
- if (scope.scopeLevel) params.set('scopeLevel', scope.scopeLevel);
- if (scope.storeId) params.set('storeId', scope.storeId);
- if (scope.district) params.set('district', scope.district);
- if (scope.roomId) params.set('roomId', scope.roomId);
- const query = params.toString();
- const path = query ? `/dashboard/overview?${query}` : '/dashboard/overview';
- return this.api.getResult<DashboardOverviewDto>(path);
- }
- }
|