charts.ts 1.4 KB

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