dashboard-api.service.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { Injectable, inject } from '@angular/core';
  2. import { ApiClientService } from './api-client.service';
  3. import type { GroupChatDto } from './qiwe-api.service';
  4. import type { StoreDto } from './qiwe-api.service';
  5. export interface DashboardStatsDto {
  6. totalGroups: number;
  7. totalMembers: number;
  8. activeGroupRate: number;
  9. avgHealthScore: number;
  10. complianceRate: number;
  11. riskEventCount: number;
  12. pendingWorkOrders: number;
  13. intentLeadCount: number;
  14. conversionRate: number;
  15. }
  16. export interface DashboardScopeGroupOption {
  17. roomId: string;
  18. roomName: string;
  19. district: string;
  20. }
  21. export interface ResolvedScopeDto {
  22. level: 'global' | 'region' | 'store' | 'city' | 'district' | 'group';
  23. storeId?: string;
  24. storeIds?: string[];
  25. regionCode?: string;
  26. storeName?: string;
  27. district?: string;
  28. roomId?: string;
  29. label?: string;
  30. }
  31. export interface DashboardOverviewDto {
  32. stats: DashboardStatsDto;
  33. activityDistribution: { high: number; medium: number; low: number; inactive: number };
  34. lifecycleDistribution: Array<{ phase: string; label: string; count: number }>;
  35. healthGradeDistribution: Record<string, number>;
  36. storeComparison: Array<{ storeName: string; groupCount: number }>;
  37. districtComparison: Array<{ district: string; groupCount: number }>;
  38. topGroups: GroupChatDto[];
  39. recentRiskEvents: [];
  40. stores: StoreDto[];
  41. districts: string[];
  42. groupsByDistrict: Record<string, DashboardScopeGroupOption[]>;
  43. scope: ResolvedScopeDto;
  44. viewer: { id: string; name: string; role: string; storeId: string; storeName: string; regionCode?: string };
  45. }
  46. export interface DashboardScopeQuery {
  47. scopeLevel?: 'global' | 'region' | 'store' | 'city' | 'district' | 'group';
  48. storeId?: string;
  49. district?: string;
  50. roomId?: string;
  51. }
  52. @Injectable({ providedIn: 'root' })
  53. export class DashboardApiService {
  54. private readonly api = inject(ApiClientService);
  55. getOverview(scope: DashboardScopeQuery = {}) {
  56. const params = new URLSearchParams();
  57. if (scope.scopeLevel) params.set('scopeLevel', scope.scopeLevel);
  58. if (scope.storeId) params.set('storeId', scope.storeId);
  59. if (scope.district) params.set('district', scope.district);
  60. if (scope.roomId) params.set('roomId', scope.roomId);
  61. const query = params.toString();
  62. const path = query ? `/dashboard/overview?${query}` : '/dashboard/overview';
  63. return this.api.getResult<DashboardOverviewDto>(path);
  64. }
  65. }