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

Function addTaskToProject

src/services/taskRelationshipActions.ts:67–102  ·  view source on GitHub ↗
(
	plugin: TaskNotesPlugin,
	task: TaskInfo,
	projectFile: TFile
)

Source from the content-addressed store, hash-verified

65}
66
67export async function addTaskToProject(
68 plugin: TaskNotesPlugin,
69 task: TaskInfo,
70 projectFile: TFile
71): Promise<TaskInfo | null> {
72 const projectReference = generateLink(
73 plugin.app,
74 projectFile,
75 task.path,
76 "",
77 "",
78 plugin.settings.useFrontmatterMarkdownLinks
79 );
80 const legacyReference = `[[${projectFile.basename}]]`;
81 const currentProjects = Array.isArray(task.projects) ? task.projects : [];
82
83 if (currentProjects.includes(projectReference) || currentProjects.includes(legacyReference)) {
84 publishUserNotice(
85 plugin.emitter,
86 translate(plugin, "contextMenus.task.organization.notices.alreadyInProject")
87 );
88 return null;
89 }
90
91 const sanitizedProjects = currentProjects.filter((entry) => entry !== legacyReference);
92 const updatedProjects = [...sanitizedProjects, projectReference];
93 const updatedTask = await plugin.updateTaskProperty(task, "projects", updatedProjects);
94
95 publishUserNotice(
96 plugin.emitter,
97 translate(plugin, "contextMenus.task.organization.notices.addedToProject", {
98 project: projectFile.basename,
99 })
100 );
101 return updatedTask;
102}
103
104export async function assignTaskAsSubtask(
105 plugin: TaskNotesPlugin,

Calls 4

generateLinkFunction · 0.90
publishUserNoticeFunction · 0.90
updateTaskPropertyMethod · 0.80
translateFunction · 0.70

Tested by

no test coverage detected