import axios from './instance' import { params } from '@/env' import { GUIDE_LIST, INSERT_GUIDE, UPDATE_GUIDE, DELETE_GUIDE, } from './constant' interface ServiceGuide { fusionGuideId: number cover: string title: string showTaggings?: boolean showMeasure?: boolean showMonitor?: boolean showPath?: boolean } export interface Guide { id: string cover: string title: string recoveryContent?: string changeAnimationStatus?: boolean showTagging: boolean showMeasure: boolean showMonitor: boolean showPath: boolean } export type Guides = Guide[] const serviceToLocal = (serviceGuide: ServiceGuide): Guide => ({ showMeasure: true, showMonitor: true, showPath: true, ...serviceGuide, showTagging: serviceGuide.showTaggings === undefined ? true : serviceGuide.showTaggings, id: serviceGuide.fusionGuideId.toString(), }) const localToService = (guide: Guide): ServiceGuide => ({ ...guide, showTaggings: guide.showTagging, fusionGuideId: Number(guide.id), }) export const fetchGuides = async () => { const guides = await axios.get(GUIDE_LIST, { params: { caseId: params.caseId } }) return guides.map(serviceToLocal) } export const postAddGuide = async (guide: Guide) => { const addData = { ...localToService(guide), caseId: params.caseId, fusionGuideId: undefined } const serviceData = await axios.post(INSERT_GUIDE, addData) return serviceToLocal(serviceData) } export const postUpdateGuide = async (guide: Guide) => { return axios.post(UPDATE_GUIDE, { ...localToService(guide)}) } export const postDeleteGuide = (id: Guide['id']) => { return axios.post(DELETE_GUIDE, { fusionGuideId: Number(id) }) }