sync-mutation.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { postJSON, deleteJSON } from '../../../infrastructure/fetch-json'
  2. export function syncRename(
  3. projectId: string,
  4. entityType: string,
  5. entityId: string,
  6. newName: string
  7. ) {
  8. return postJSON(
  9. `/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/rename`,
  10. {
  11. body: {
  12. name: newName,
  13. },
  14. }
  15. )
  16. }
  17. export function syncDelete(
  18. projectId: string,
  19. entityType: string,
  20. entityId: string
  21. ) {
  22. return deleteJSON(
  23. `/project/${projectId}/${getEntityPathName(entityType)}/${entityId}`
  24. )
  25. }
  26. export function syncMove(
  27. projectId: string,
  28. entityType: string,
  29. entityId: string,
  30. toFolderId: string
  31. ) {
  32. return postJSON(
  33. `/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/move`,
  34. {
  35. body: {
  36. folder_id: toFolderId,
  37. },
  38. }
  39. )
  40. }
  41. export function syncCreateEntity(
  42. projectId: string,
  43. parentFolderId: string,
  44. newEntityData: {
  45. endpoint: 'doc' | 'folder' | 'linked-file'
  46. [key: string]: unknown
  47. }
  48. ) {
  49. const { endpoint, ...newEntity } = newEntityData
  50. return postJSON(`/project/${projectId}/${endpoint}`, {
  51. body: {
  52. parent_folder_id: parentFolderId,
  53. ...newEntity,
  54. },
  55. })
  56. }
  57. function getEntityPathName(entityType: string) {
  58. return entityType === 'fileRef' ? 'file' : entityType
  59. }