All files / main/services taskService.ts

82.35% Statements 14/17
83.33% Branches 5/6
75% Functions 6/8
80% Lines 12/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43        4x             2x 2x 1x       2x 2x 1x       1x               1x 1x 1x           1x      
import type { Task } from '@shared/types'
import type { TaskRepository } from '@main/ports/repositories'
 
export class TaskService {
  constructor(private readonly tasks: TaskRepository) {}
 
  list(): Promise<Task[]> {
    return this.tasks.list()
  }
 
  async create(title: string): Promise<Task> {
    const trimmed = title.trim()
    if (!trimmed) throw new Error('Task title is required')
    return this.tasks.create(trimmed)
  }
 
  update(id: string, title: string): Promise<Task> {
    const trimmed = title.trim()
    if (!trimmed) throw new Error('Task title is required')
    return this.tasks.updateTitle(id, trimmed)
  }
 
  complete(id: string): Promise<Task> {
    return this.tasks.complete(id)
  }
 
  restore(id: string): Promise<Task> {
    return this.tasks.restore(id)
  }
 
  reorder(ids: string[]): Promise<void> {
    const uniqueIds = [...new Set(ids)]
    Eif (uniqueIds.length !== ids.length) {
      throw new Error('Task reorder payload contains duplicate ids')
    }
    return this.tasks.reorderActive(ids)
  }
 
  delete(id: string): Promise<void> {
    return this.tasks.delete(id)
  }
}