UNPKG

@stevescruz/task-master

Version:

A command-line todo list that allows you to write your tasks, set priorities, view existing tasks and view the next tasks due.

25 lines (18 loc) 596 B
const getTimeSince = require('../shared/utils/getTimeSince'); class DeleteTaskService { constructor(tasksRepository) { this.tasksRepository = tasksRepository; } async execute(id) { if(!id) { throw new Error(`Cannot delete a task without providing an id.`); } const task = await this.tasksRepository.removeById(id); if(!task) { throw new Error(`A task with the id {${id}} does not exist.`); } task.age = getTimeSince(task.timestamp); return task; } } module.exports = DeleteTaskService;