( taskListId: string, taskId: string, )
| 392 | } |
| 393 | |
| 394 | export async function deleteTask( |
| 395 | taskListId: string, |
| 396 | taskId: string, |
| 397 | ): Promise<boolean> { |
| 398 | const path = getTaskPath(taskListId, taskId) |
| 399 | |
| 400 | try { |
| 401 | // Update high water mark before deleting to prevent ID reuse |
| 402 | const numericId = parseInt(taskId, 10) |
| 403 | if (!isNaN(numericId)) { |
| 404 | const currentMark = await readHighWaterMark(taskListId) |
| 405 | if (numericId > currentMark) { |
| 406 | await writeHighWaterMark(taskListId, numericId) |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | // Delete the task file |
| 411 | try { |
| 412 | await unlink(path) |
| 413 | } catch (e) { |
| 414 | const code = getErrnoCode(e) |
| 415 | if (code === 'ENOENT') { |
| 416 | return false |
| 417 | } |
| 418 | throw e |
| 419 | } |
| 420 | |
| 421 | // Remove references to this task from other tasks |
| 422 | const allTasks = await listTasks(taskListId) |
| 423 | for (const task of allTasks) { |
| 424 | const newBlocks = task.blocks.filter(id => id !== taskId) |
| 425 | const newBlockedBy = task.blockedBy.filter(id => id !== taskId) |
| 426 | if ( |
| 427 | newBlocks.length !== task.blocks.length || |
| 428 | newBlockedBy.length !== task.blockedBy.length |
| 429 | ) { |
| 430 | await updateTask(taskListId, task.id, { |
| 431 | blocks: newBlocks, |
| 432 | blockedBy: newBlockedBy, |
| 433 | }) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | notifyTasksUpdated() |
| 438 | return true |
| 439 | } catch { |
| 440 | return false |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | export async function listTasks(taskListId: string): Promise<Task[]> { |
| 445 | const dir = getTasksDir(taskListId) |
no test coverage detected