@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) • 639 B
JavaScript
const getTimeSince = require('../shared/utils/getTimeSince');
class FinalizeTaskService {
constructor(tasksRepository) {
this.tasksRepository = tasksRepository;
}
async execute(id) {
if(!id) {
throw new Error('Cannot mark a task as done without providing a corresponding id.');
}
const task = await this.tasksRepository.updateById(id, { status: 'done' });
if(!task) {
throw new Error(`A task with the id {${id}} does not exist.`);
}
task.age = getTimeSince(task.timestamp);
return task;
}
}
module.exports = FinalizeTaskService;