From b101da8da586014e2f8c4e97f28518f4d318d9b7 Mon Sep 17 00:00:00 2001 From: Michal Feher Date: Fri, 9 Jan 2026 13:44:27 +0100 Subject: [PATCH] no message --- app/.env.development | 2 +- be/app/Http/Controllers/SubTaskController.php | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/.env.development b/app/.env.development index 2002315..24f43d7 100644 --- a/app/.env.development +++ b/app/.env.development @@ -1 +1 @@ -VUE_APP_WAXIOS_URL=https://taskmanager.internal.studiotem.com/api/ \ No newline at end of file +VUE_APP_WAXIOS_URL=http://127.0.0.1:8001/api/ \ No newline at end of file diff --git a/be/app/Http/Controllers/SubTaskController.php b/be/app/Http/Controllers/SubTaskController.php index 62ef511..e3d3a43 100644 --- a/be/app/Http/Controllers/SubTaskController.php +++ b/be/app/Http/Controllers/SubTaskController.php @@ -418,13 +418,32 @@ class SubTaskController extends Controller ], 400); } - // Validácia - každý zamestnanec musí mať id a duration - foreach ($employees as $employee) { - if (!isset($employee['id']) || !isset($employee['duration'])) { + // Validácia a doplnenie duration z timeblocks + foreach ($employees as $key => $employee) { + if (!isset($employee['id'])) { return response()->json([ - 'message' => 'Draft cannot be published. Each employee must have id and duration.', + 'message' => 'Draft cannot be published. Each employee must have id.', ], 400); } + + // Ak duration nie je nastavený, vypočítaj ho z timeblocks + if (!isset($employee['duration']) || $employee['duration'] === null) { + if (isset($employee['timeblocks']) && !empty($employee['timeblocks'])) { + $totalDuration = 0; + foreach ($employee['timeblocks'] as $timeblock) { + if (isset($timeblock['start']) && isset($timeblock['end'])) { + $start = Carbon::parse($timeblock['start']); + $end = Carbon::parse($timeblock['end']); + $totalDuration += $end->diffInMinutes($start); + } + } + $employees[$key]['duration'] = $totalDuration; + } else { + return response()->json([ + 'message' => 'Draft cannot be published. Each employee must have duration or timeblocks.', + ], 400); + } + } } $mastertask = $draft->mastertask;