import axios from "./instance"; import { params } from "@/env"; import { PATH_LIST, DELETE_PATH, INSERT_PATH, UPDATE_PATH } from "./constant"; interface ServerPath { id: number; path: string; } export interface Path { id: string; name: string; showName: boolean; linePosition?: { position: SceneLocalPos; modelId: string; }; lineWidth: number; lineColor: string; lineAltitudeAboveGround: number; fontSize: number; showDirection: boolean; reverseDirection: boolean; globalVisibility: boolean; visibilityRange: number; points: { name: string; position: SceneLocalPos; modelId: string; }[]; } export type Paths = Path[]; const serviceToLocal = (servicePath: ServerPath): Path => ({ ...JSON.parse(servicePath.path), id: servicePath.id.toString(), }); const localToService = (path: Path): ServerPath => ({ id: Number(path.id), path: JSON.stringify(path), }); export const fetchPaths = async () => { const staggings = await axios.get(PATH_LIST, { params: { caseId: params.caseId }, }); return staggings.map(serviceToLocal); }; export const postAddPath = async (path: Path) => { const stagging = await axios.post(INSERT_PATH, { ...localToService(path), caseId: params.caseId, }); return serviceToLocal(stagging); }; export const postUpdatePath = (path: Path) => { return axios.post(UPDATE_PATH, { ...localToService(path), caseId: params.caseId, }); }; export const postDeletePath = (id: Path["id"]) => { return axios.post(DELETE_PATH, { pathId: id }); };