MCPcopy Create free account
hub / github.com/Noumena-Network/code / deleteTask

Function deleteTask

src/utils/tasks.ts:394–442  ·  view source on GitHub ↗
(
  taskListId: string,
  taskId: string,
)

Source from the content-addressed store, hash-verified

392}
393
394export 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
444export async function listTasks(taskListId: string): Promise<Task[]> {
445 const dir = getTasksDir(taskListId)

Callers 2

callFunction · 0.85
callFunction · 0.85

Calls 8

getTaskPathFunction · 0.85
readHighWaterMarkFunction · 0.85
writeHighWaterMarkFunction · 0.85
unlinkFunction · 0.85
getErrnoCodeFunction · 0.85
listTasksFunction · 0.85
updateTaskFunction · 0.85
notifyTasksUpdatedFunction · 0.85

Tested by

no test coverage detected