* Toggle the status of a task between completed and open
(task: TaskInfo)
| 534 | * Toggle the status of a task between completed and open |
| 535 | */ |
| 536 | async toggleStatus(task: TaskInfo): Promise<TaskInfo> { |
| 537 | try { |
| 538 | // Determine new status |
| 539 | const isCurrentlyCompleted = this.plugin.statusManager.isCompletedStatus(task.status); |
| 540 | const newStatus = isCurrentlyCompleted |
| 541 | ? this.plugin.settings.defaultTaskStatus // Revert to default open status |
| 542 | : this.plugin.statusManager.getCompletedStatuses()[0] || "done"; // Set to first completed status |
| 543 | |
| 544 | return await this.updateProperty(task, "status", newStatus); |
| 545 | } catch (error) { |
| 546 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 547 | tasknotesLogger.error("Error toggling task status:", { |
| 548 | category: "persistence", |
| 549 | operation: "toggling-task-status", |
| 550 | details: { |
| 551 | stack: error instanceof Error ? error.stack : undefined, |
| 552 | taskPath: task.path, |
| 553 | currentStatus: task.status, |
| 554 | }, |
| 555 | error: errorMessage, |
| 556 | }); |
| 557 | |
| 558 | throw new Error(`Failed to toggle task status: ${errorMessage}`); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Update a single property of a task following the deterministic data flow pattern |
no test coverage detected