123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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<ServiceGuide[]>(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<ServiceGuide>(INSERT_GUIDE, addData)
- return serviceToLocal(serviceData)
- }
- export const postUpdateGuide = async (guide: Guide) => {
- return axios.post<undefined>(UPDATE_GUIDE, { ...localToService(guide)})
- }
- export const postDeleteGuide = (id: Guide['id']) => {
- return axios.post<undefined>(DELETE_GUIDE, { fusionGuideId: Number(id) })
- }
-
|