charts.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import axios from 'axios';
  2. interface ChartDataResponse<T> {
  3. message: string;
  4. data: T;
  5. }
  6. interface UserActivityData {
  7. date: string;
  8. count: number;
  9. }
  10. interface FileUploadsData {
  11. month: string;
  12. count: number;
  13. }
  14. interface FileTypesData {
  15. type: string;
  16. value: number;
  17. }
  18. interface DashboardOverviewData {
  19. userCount: number;
  20. fileCount: number;
  21. articleCount: number;
  22. todayLoginCount: number;
  23. }
  24. export const ChartAPI = {
  25. getUserActivity: async (): Promise<ChartDataResponse<UserActivityData[]>> => {
  26. try {
  27. const response = await axios.get('/charts/user-activity');
  28. return response.data;
  29. } catch (error) {
  30. throw error;
  31. }
  32. },
  33. getFileUploads: async (): Promise<ChartDataResponse<FileUploadsData[]>> => {
  34. try {
  35. const response = await axios.get('/charts/file-uploads');
  36. return response.data;
  37. } catch (error) {
  38. throw error;
  39. }
  40. },
  41. getFileTypes: async (): Promise<ChartDataResponse<FileTypesData[]>> => {
  42. try {
  43. const response = await axios.get('/charts/file-types');
  44. return response.data;
  45. } catch (error) {
  46. throw error;
  47. }
  48. },
  49. getDashboardOverview: async (): Promise<ChartDataResponse<DashboardOverviewData>> => {
  50. try {
  51. const response = await axios.get('/charts/dashboard-overview');
  52. return response.data;
  53. } catch (error) {
  54. throw error;
  55. }
  56. }
  57. };