From ba309d9a1f809de3c49bee55153eb1605f428597 Mon Sep 17 00:00:00 2001 From: mahdihty Date: Wed, 3 Mar 2021 15:55:35 +0330 Subject: [PATCH] bug fix work, comment, task cruds during test convert all task relation from tagTask to tags --- app/Http/Controllers/TaskController.php | 24 ++++++++++++------------ app/Http/Controllers/WorkController.php | 6 +++--- app/Http/Resources/TaskResource.php | 2 +- app/Models/Task.php | 6 ++---- app/Models/Work.php | 2 +- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 6a9b8de..02ef09b 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -6,7 +6,7 @@ use Carbon\Carbon; use App\Models\Task; use App\Models\Work; use App\Models\TagTask; -use App\Rules\maxBound; +use App\Rules\MaxBound; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\DB; @@ -30,20 +30,20 @@ class TaskController extends Controller return $request->filled('group') ? $tasks->get()->groupBy($request->group) ->map(function ($q) { return $q->keyBy('status_id'); }) - : /*response()->json(collect(['now' => Carbon::now()->toDateString()])->merge(*/new TaskCollection($tasks->paginate($per_page));//)); + : new TaskCollection($tasks->paginate($per_page)); } public function indexValidation($request) { $bound = 10; $this->validate($request, [ - 'filter.project_id' => [new maxBound($bound)] , - 'filter.creator_id' => [new maxBound($bound)] , - 'filter.assignee_id' => [new maxBound($bound)] , - 'filter.system_id' => [new maxBound($bound)] , - 'filter.workflow_id' => [new maxBound($bound)] , - 'filter.status_id' => [new maxBound($bound)] , - 'filter.approver_id' => [new maxBound($bound)] , + 'filter.project_id' => [new MaxBound($bound)] , + 'filter.creator_id' => [new MaxBound($bound)] , + 'filter.assignee_id' => [new MaxBound($bound)] , + 'filter.system_id' => [new MaxBound($bound)] , + 'filter.workflow_id' => [new MaxBound($bound)] , + 'filter.status_id' => [new MaxBound($bound)] , + 'filter.approver_id' => [new MaxBound($bound)] , 'filter.priority_min' => 'nullable|numeric|between:1,10' , 'filter.priority_max' => 'nullable|numeric|between:1,10' , 'filter.ready_to_test' => 'nullable|boolean' , @@ -55,7 +55,7 @@ class TaskController extends Controller { $query = Task::where('business_id', $business); $taskQ = QueryBuilder::for($query) - ->with('tagTask') +// ->with('tags') ->select(DB::raw('tasks.* , (spent_time - estimated_time) as over_spent')) ->allowedFilters([ AllowedFilter::exact('project_id'), @@ -140,7 +140,7 @@ class TaskController extends Controller public function store($business, $project, Request $request) { -// permit('projectTasks', ['project_id' => $project]); + permit('projectTasks', ['project_id' => $project]); $task = Task::create($request->merge( ['business_id' => $business, 'project_id' => $project, 'creator_id' => \auth()->id()] @@ -167,7 +167,7 @@ class TaskController extends Controller * 1) guest's only can see self task * 2) user is active in project */ - public function show($business, $task, $project =null) + public function show($business, $project, $task) { $task = Task::findOrFail($task); $project = $task->project_id; diff --git a/app/Http/Controllers/WorkController.php b/app/Http/Controllers/WorkController.php index 89b00f9..d7f6d1f 100644 --- a/app/Http/Controllers/WorkController.php +++ b/app/Http/Controllers/WorkController.php @@ -124,7 +124,7 @@ class WorkController extends Controller // 'work_start' => Work::where('task_id', $taskModel->id)->orderBy('started_at')->first()->started_at ?? null, // 'spent_time' => $taskModel->spent_time + $diff_in_min // ]); - return $taskModel->load(['tagTask'=> fn($q) => $q->select('id', 'tag_id', 'task_id'), 'works', 'comments']); + return $taskModel->load(['tags', 'works', 'comments']); } public function storeValidation($request, $taskModel) @@ -187,7 +187,7 @@ class WorkController extends Controller // 'work_start' => Work::where('task_id', $taskModel->id)->orderBy('started_at')->first()->started_at ?? null, // 'spent_time' => ($taskModel->spent_time - $old_diff_in_min) + $new_diff_in_min // ]); - return $taskModel->load(['tagTask'=> fn($q) => $q->select('id', 'tag_id', 'task_id'), 'works', 'comments']); + return $taskModel->load(['tags', 'works', 'comments']); } public function updateValidation($request, $taskModel, $workModel) @@ -237,6 +237,6 @@ class WorkController extends Controller 'work_start' => Work::where('task_id', $taskModel->id)->orderBy('started_at')->first()->started_at ?? null, 'spent_time' => ($taskModel->spent_time - $diff_in_min) ]); - return $taskModel->load(['tagTask'=> fn($q) => $q->select('id', 'tag_id', 'task_id'), 'works','comments']); + return $taskModel->load(['tags', 'works','comments']); } } diff --git a/app/Http/Resources/TaskResource.php b/app/Http/Resources/TaskResource.php index 6737a5a..eab56f3 100644 --- a/app/Http/Resources/TaskResource.php +++ b/app/Http/Resources/TaskResource.php @@ -21,7 +21,7 @@ class TaskResource extends JsonResource } } - $resource['tags'] = $this->tagTask()->pluck('tag_id')->toArray(); + $resource['tags'] = $this->tags; $resource['works'] = $this->works; $resource['comments'] = $this->comments; diff --git a/app/Models/Task.php b/app/Models/Task.php index 5923ac9..ffef4f7 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -158,12 +158,10 @@ class Task extends Model public function tags() { - return $this->belongsToMany( - Tag::class, 'tag_task', 'task_id', 'tag_id', - 'id', 'id', __FUNCTION__ - )->using(ReportableRelation::class); + return $this->belongsToMany(Tag::class)->using(ReportableRelation::class); } + // Todo: are we need this relation???? public function tagTask() { return $this->hasMany(TagTask::class, 'task_id', 'id'); diff --git a/app/Models/Work.php b/app/Models/Work.php index c84648e..0b6ce81 100644 --- a/app/Models/Work.php +++ b/app/Models/Work.php @@ -37,7 +37,7 @@ class Work extends Model 'ended_at' => [ 'required', 'date_format:Y-m-d H:i', 'after:'.$started_at, function ($attribute, $value, $fail) use ($ended_at, $started_at) { - $works = \App\Work::where([ + $works = $this::where([ ['ended_at', '>', $started_at], ['ended_at', '<', $ended_at], ])->orWhere([