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