sync-mutation.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { postJSON, deleteJSON } from '../../../infrastructure/fetch-json'
  2. export function syncRename(projectId, entityType, entityId, newName) {
  3. return postJSON(
  4. `/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/rename`,
  5. {
  6. body: {
  7. name: newName
  8. }
  9. }
  10. )
  11. }
  12. export function syncDelete(projectId, entityType, entityId) {
  13. return deleteJSON(
  14. `/project/${projectId}/${getEntityPathName(entityType)}/${entityId}`
  15. )
  16. }
  17. export function syncMove(projectId, entityType, entityId, toFolderId) {
  18. return postJSON(
  19. `/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/move`,
  20. {
  21. body: {
  22. folder_id: toFolderId
  23. }
  24. }
  25. )
  26. }
  27. export function syncCreateEntity(projectId, parentFolderId, newEntityData) {
  28. const { endpoint, ...newEntity } = newEntityData
  29. return postJSON(`/project/${projectId}/${endpoint}`, {
  30. body: {
  31. parent_folder_id: parentFolderId,
  32. ...newEntity
  33. }
  34. })
  35. }
  36. function getEntityPathName(entityType) {
  37. return entityType === 'fileRef' ? 'file' : entityType
  38. }