overleaf-cep/services/web/frontend/js/features/file-tree/util/sync-mutation.ts
David 2365d8c199 Merge pull request #22836 from overleaf/dp-filetree-typescript
Convert file-tree util files to typescript

GitOrigin-RevId: bdf8d0655a543a216f028bc8477c3ee47aba5566
2025-01-22 09:04:56 +00:00

64 lines
1.3 KiB
TypeScript

import { postJSON, deleteJSON } from '../../../infrastructure/fetch-json'
export function syncRename(
projectId: string,
entityType: string,
entityId: string,
newName: string
) {
return postJSON(
`/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/rename`,
{
body: {
name: newName,
},
}
)
}
export function syncDelete(
projectId: string,
entityType: string,
entityId: string
) {
return deleteJSON(
`/project/${projectId}/${getEntityPathName(entityType)}/${entityId}`
)
}
export function syncMove(
projectId: string,
entityType: string,
entityId: string,
toFolderId: string
) {
return postJSON(
`/project/${projectId}/${getEntityPathName(entityType)}/${entityId}/move`,
{
body: {
folder_id: toFolderId,
},
}
)
}
export function syncCreateEntity(
projectId: string,
parentFolderId: string,
newEntityData: {
endpoint: 'doc' | 'folder' | 'linked-file'
[key: string]: unknown
}
) {
const { endpoint, ...newEntity } = newEntityData
return postJSON(`/project/${projectId}/${endpoint}`, {
body: {
parent_folder_id: parentFolderId,
...newEntity,
},
})
}
function getEntityPathName(entityType: string) {
return entityType === 'fileRef' ? 'file' : entityType
}