monitor.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import axios from "./instance";
  2. import { params } from "@/env";
  3. import {
  4. GUIDE_MONITOR_LIST,
  5. UPDATE_MONITOR,
  6. DELETE_MONITOR,
  7. INSERT_MONITOR,
  8. } from "./constant";
  9. import type { Guide } from "./guide";
  10. interface ServiceMonitor {
  11. id: string;
  12. title: string;
  13. content: string;
  14. }
  15. export interface Monitor {
  16. id: string;
  17. title: string;
  18. content: string;
  19. }
  20. export type Monitors = Monitor[];
  21. const serviceToLocal = (servicePath: ServiceMonitor): Monitor => ({
  22. ...servicePath,
  23. });
  24. const localToService = (path: Monitor): ServiceMonitor => ({
  25. ...path,
  26. });
  27. export const fetchMonitors = async () => {
  28. return [
  29. {
  30. id: 1,
  31. title: "室内监控",
  32. content: "",
  33. },
  34. {
  35. id: 2,
  36. title: "室内监控",
  37. content: "",
  38. },
  39. ];
  40. const monitors = await axios.get<ServiceMonitor[]>(GUIDE_MONITOR_LIST);
  41. return monitors.map(serviceToLocal);
  42. };
  43. export const postInsertMonitor = async (monitor: Monitor) => {
  44. const smonitor = await axios.post<ServiceMonitor>(INSERT_MONITOR, {
  45. ...localToService(monitor),
  46. fusionId: params.caseId,
  47. });
  48. return serviceToLocal(smonitor);
  49. };
  50. export const postUpdateMonitor = async (monitor: Monitor) => {
  51. return axios.post<undefined>(UPDATE_MONITOR, { ...localToService(monitor) });
  52. };
  53. export const postDeleteMonitor = (id: Monitor["id"]) => {
  54. return axios.post<undefined>(DELETE_MONITOR, { id: Number(id) });
  55. };