( path: string, targetFolder: string, context?: TaskNotesMutationContext )
| 2013 | } |
| 2014 | |
| 2015 | async moveTask( |
| 2016 | path: string, |
| 2017 | targetFolder: string, |
| 2018 | context?: TaskNotesMutationContext |
| 2019 | ): Promise<TaskInfo> { |
| 2020 | const task = await this.requireTask(path); |
| 2021 | const file = this.requireTaskFile(task.path); |
| 2022 | const normalizedFolder = normalizePath(targetFolder); |
| 2023 | const newPath = normalizedFolder ? `${normalizedFolder}/${file.name}` : file.name; |
| 2024 | |
| 2025 | if (newPath === task.path) { |
| 2026 | return copyTaskInfo(task); |
| 2027 | } |
| 2028 | |
| 2029 | return this.withMutationContext([task.path, newPath], context, async () => { |
| 2030 | if (normalizedFolder) { |
| 2031 | await ensureFolderExists(this.plugin.app.vault, normalizedFolder); |
| 2032 | } |
| 2033 | |
| 2034 | const existingFile = this.plugin.app.vault.getAbstractFileByPath(newPath); |
| 2035 | if (existingFile) { |
| 2036 | throw new TaskNotesApiError( |
| 2037 | "file_already_exists", |
| 2038 | `Cannot move task to "${newPath}" because a file already exists`, |
| 2039 | { status: 409, details: { path: newPath } } |
| 2040 | ); |
| 2041 | } |
| 2042 | |
| 2043 | await this.plugin.app.fileManager.renameFile(file, newPath); |
| 2044 | |
| 2045 | const updatedTask = copyTaskInfo({ |
| 2046 | ...task, |
| 2047 | id: task.id && task.id !== task.path ? task.id : newPath, |
| 2048 | path: newPath, |
| 2049 | }); |
| 2050 | |
| 2051 | this.plugin.cacheManager.clearCacheEntry(task.path); |
| 2052 | this.plugin.cacheManager.updateTaskInfoInCache(newPath, updatedTask); |
| 2053 | this.plugin.emitter.trigger(EVENT_TASK_UPDATED, { |
| 2054 | path: newPath, |
| 2055 | originalTask: task, |
| 2056 | updatedTask, |
| 2057 | }); |
| 2058 | |
| 2059 | return updatedTask; |
| 2060 | }); |
| 2061 | } |
| 2062 | |
| 2063 | async deleteTask(path: string, context?: TaskNotesMutationContext): Promise<void> { |
| 2064 | const task = await this.requireTask(path); |
no test coverage detected