From de07057694fddf98d31f6a959e3ce6fcc71bee92 Mon Sep 17 00:00:00 2001 From: sgarnica1 Date: Thu, 6 Jun 2024 09:38:40 -0600 Subject: [PATCH] fix(tasks): do not create task if error --- src/core/app/services/task.service.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/app/services/task.service.ts b/src/core/app/services/task.service.ts index 40e406c..d971667 100644 --- a/src/core/app/services/task.service.ts +++ b/src/core/app/services/task.service.ts @@ -121,11 +121,6 @@ async function createTask(newTask: BareboneTask): Promise { throw new Error('Worked hours must be lower than or equal to 1000'); } - const createdTask = await TaskRepository.createTask(task); - if (!createdTask) { - throw new Error('Task already exists'); - } - if (newTask.endDate && project.endDate && !dateSmallerOrEqualThanOther(newTask.endDate, project.endDate)) throw new Error("Task's end date cannot be after the project's end date"); @@ -135,6 +130,11 @@ async function createTask(newTask: BareboneTask): Promise { if (newTask.startDate && project.endDate && !dateSmallerOrEqualThanOther(newTask.startDate, project.endDate)) throw new Error("Task's start date cannot be after the project's end date"); + const createdTask = await TaskRepository.createTask(task); + if (!createdTask) { + throw new Error('Task already exists'); + } + if (newTask.idEmployee) { const employee = await EmployeeRepository.findById(newTask.idEmployee); if (!employee) {