1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import axios from "./instance";
- import { params } from "@/env";
- import {
- GUIDE_MONITOR_LIST,
- UPDATE_MONITOR,
- DELETE_MONITOR,
- INSERT_MONITOR,
- } from "./constant";
- import type { Guide } from "./guide";
- interface ServiceMonitor {
- id: string;
- title: string;
- content: string;
- }
- export interface Monitor {
- id: string;
- title: string;
- content: string;
- }
- export type Monitors = Monitor[];
- const serviceToLocal = (servicePath: ServiceMonitor): Monitor => ({
- ...servicePath,
- });
- const localToService = (path: Monitor): ServiceMonitor => ({
- ...path,
- });
- export const fetchMonitors = async () => {
- return [
- {
- id: 1,
- title: "室内监控",
- content: "",
- },
- {
- id: 2,
- title: "室内监控",
- content: "",
- },
- ];
- const monitors = await axios.get<ServiceMonitor[]>(GUIDE_MONITOR_LIST);
- return monitors.map(serviceToLocal);
- };
- export const postInsertMonitor = async (monitor: Monitor) => {
- const smonitor = await axios.post<ServiceMonitor>(INSERT_MONITOR, {
- ...localToService(monitor),
- fusionId: params.caseId,
- });
- return serviceToLocal(smonitor);
- };
- export const postUpdateMonitor = async (monitor: Monitor) => {
- return axios.post<undefined>(UPDATE_MONITOR, { ...localToService(monitor) });
- };
- export const postDeleteMonitor = (id: Monitor["id"]) => {
- return axios.post<undefined>(DELETE_MONITOR, { id: Number(id) });
- };
|