guide.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import axios from './instance'
  2. import { params } from '@/env'
  3. import {
  4. GUIDE_LIST,
  5. INSERT_GUIDE,
  6. UPDATE_GUIDE,
  7. DELETE_GUIDE,
  8. } from './constant'
  9. interface ServiceGuide {
  10. fusionGuideId: number
  11. cover: string
  12. title: string
  13. showTaggings?: boolean
  14. showMeasure?: boolean
  15. showMonitor?: boolean
  16. showPath?: boolean
  17. }
  18. export interface Guide {
  19. id: string
  20. cover: string
  21. title: string
  22. recoveryContent?: string
  23. changeAnimationStatus?: boolean
  24. showTagging: boolean
  25. showMeasure: boolean
  26. showMonitor: boolean
  27. showPath: boolean
  28. }
  29. export type Guides = Guide[]
  30. const serviceToLocal = (serviceGuide: ServiceGuide): Guide => ({
  31. showMeasure: true,
  32. showMonitor: true,
  33. showPath: true,
  34. ...serviceGuide,
  35. showTagging: serviceGuide.showTaggings === undefined ? true : serviceGuide.showTaggings,
  36. id: serviceGuide.fusionGuideId.toString(),
  37. })
  38. const localToService = (guide: Guide): ServiceGuide => ({
  39. ...guide,
  40. showTaggings: guide.showTagging,
  41. fusionGuideId: Number(guide.id),
  42. })
  43. export const fetchGuides = async () => {
  44. const guides = await axios.get<ServiceGuide[]>(GUIDE_LIST, { params: { caseId: params.caseId } })
  45. return guides.map(serviceToLocal)
  46. }
  47. export const postAddGuide = async (guide: Guide) => {
  48. const addData = { ...localToService(guide), caseId: params.caseId, fusionGuideId: undefined }
  49. const serviceData = await axios.post<ServiceGuide>(INSERT_GUIDE, addData)
  50. return serviceToLocal(serviceData)
  51. }
  52. export const postUpdateGuide = async (guide: Guide) => {
  53. return axios.post<undefined>(UPDATE_GUIDE, { ...localToService(guide)})
  54. }
  55. export const postDeleteGuide = (id: Guide['id']) => {
  56. return axios.post<undefined>(DELETE_GUIDE, { fusionGuideId: Number(id) })
  57. }