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 (19 loc) 739 B
const AllowedChoicesTaskEnum = require('../shared/enums/AllowedChoicesTaskEnum'); class CreateTaskService { constructor(tasksRepository) { this.tasksRepository = tasksRepository; } async execute({ description, priority, tag }) { const allowedPriorities = new Set(AllowedChoicesTaskEnum.PRIORITIES); if (priority && !allowedPriorities.has(priority)) { throw new Error(`Cannot accept a priority that in not among the following options: ${Array.from(allowedPriorities)}`); } const task = await this.tasksRepository.create({ description, priority, tag, }); return task; } } module.exports = CreateTaskService;