MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / deleteTimeEntry

Method deleteTimeEntry

src/services/TaskService.ts:1880–1927  ·  view source on GitHub ↗

* Delete a specific time entry from a task

(task: TaskInfo, timeEntryIndex: number)

Source from the content-addressed store, hash-verified

1878 * Delete a specific time entry from a task
1879 */
1880 async deleteTimeEntry(task: TaskInfo, timeEntryIndex: number): Promise<TaskInfo> {
1881 const file = this.plugin.app.vault.getAbstractFileByPath(task.path);
1882 if (!(file instanceof TFile)) {
1883 throw new Error(`Cannot find task file: ${task.path}`);
1884 }
1885
1886 // Step 1: Construct new state in memory
1887 const deletePlan = buildDeleteTimeEntryPlan(task, timeEntryIndex, getCurrentTimestamp());
1888 const { updatedTask } = deletePlan;
1889
1890 // Step 2: Persist to file
1891 await this.plugin.app.fileManager.processFrontMatter(file, (frontmatter) => {
1892 const timeEntriesField = this.plugin.fieldMapper.toUserField("timeEntries");
1893 const dateModifiedField = this.plugin.fieldMapper.toUserField("dateModified");
1894 applyDeleteTimeEntryFrontmatterChange({
1895 frontmatter,
1896 timeEntriesField,
1897 dateModifiedField,
1898 timeEntryIndex: deletePlan.timeEntryIndex,
1899 dateModified: deletePlan.dateModified,
1900 });
1901 });
1902
1903 // Step 3: Wait for fresh data and update cache
1904 try {
1905 // Wait for the metadata cache to have the updated time entries
1906 if (this.plugin.cacheManager.waitForFreshTaskData) {
1907 await this.plugin.cacheManager.waitForFreshTaskData(file);
1908 }
1909 this.plugin.cacheManager.updateTaskInfoInCache(task.path, updatedTask);
1910 } catch (cacheError) {
1911 tasknotesLogger.error("Error updating cache for time entry deletion:", {
1912 category: "stale-data",
1913 operation: "updating-cache-time-entry-deletion",
1914 error: cacheError,
1915 });
1916 }
1917
1918 // Step 4: Notify system of change
1919 this.plugin.emitter.trigger(EVENT_TASK_UPDATED, {
1920 path: task.path,
1921 originalTask: task,
1922 updatedTask: updatedTask,
1923 });
1924
1925 // Step 5: Return authoritative data
1926 return updatedTask;
1927 }
1928
1929 /**
1930 * Update the completedDate field in frontmatter based on the task's status.

Callers

nothing calls this directly

Calls 9

getCurrentTimestampFunction · 0.90
getAbstractFileByPathMethod · 0.80
waitForFreshTaskDataMethod · 0.80
errorMethod · 0.80
processFrontMatterMethod · 0.65
toUserFieldMethod · 0.65
updateTaskInfoInCacheMethod · 0.65
triggerMethod · 0.65

Tested by

no test coverage detected