123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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<ServerPath[]>(PATH_LIST, {
- params: { caseId: params.caseId },
- });
- return staggings.map(serviceToLocal);
- };
- export const postAddPath = async (path: Path) => {
- const stagging = await axios.post<ServerPath>(INSERT_PATH, {
- ...localToService(path),
- caseId: params.caseId,
- });
- return serviceToLocal(stagging);
- };
- export const postUpdatePath = (path: Path) => {
- return axios.post<undefined>(UPDATE_PATH, {
- ...localToService(path),
- caseId: params.caseId,
- });
- };
- export const postDeletePath = (id: Path["id"]) => {
- return axios.post<undefined>(DELETE_PATH, { pathId: id });
- };
|