MCPcopy
hub / github.com/callumalpass/tasknotes / moveTask

Method moveTask

src/api/TaskNotesAPI.ts:2015–2061  ·  view source on GitHub ↗
(
		path: string,
		targetFolder: string,
		context?: TaskNotesMutationContext
	)

Source from the content-addressed store, hash-verified

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);

Callers 1

TaskNotesAPIClass · 0.95

Calls 11

requireTaskMethod · 0.95
requireTaskFileMethod · 0.95
withMutationContextMethod · 0.95
normalizePathFunction · 0.90
ensureFolderExistsFunction · 0.90
copyTaskInfoFunction · 0.85
getAbstractFileByPathMethod · 0.80
renameFileMethod · 0.80
clearCacheEntryMethod · 0.65
updateTaskInfoInCacheMethod · 0.65
triggerMethod · 0.65

Tested by

no test coverage detected