From e80eb17bff14c517f915fc132379de85e118e6b5 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 1 Feb 2018 13:19:37 +0800 Subject: [PATCH] Show only on progress jobs on user job list tab --- app/Http/Controllers/Users/JobsController.php | 7 +++++-- tests/Unit/Models/JobTest.php | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Users/JobsController.php b/app/Http/Controllers/Users/JobsController.php index e99d05c..8d9fec1 100644 --- a/app/Http/Controllers/Users/JobsController.php +++ b/app/Http/Controllers/Users/JobsController.php @@ -14,8 +14,11 @@ class JobsController extends Controller { public function index(User $user) { - $jobs = $user->jobs() - ->latest() + $jobs = $user->jobs()->whereHas('tasks', function ($query) { + return $query->where('progress', '<', 100); + })->whereHas('project', function ($query) { + return $query->whereIn('status_id', [2, 3]); + })->where('worker_id', $user->id) ->with(['tasks', 'project']) ->paginate(); diff --git a/tests/Unit/Models/JobTest.php b/tests/Unit/Models/JobTest.php index b4fe30a..6df8b92 100644 --- a/tests/Unit/Models/JobTest.php +++ b/tests/Unit/Models/JobTest.php @@ -47,6 +47,15 @@ class JobTest extends TestCase } /** @test */ + public function a_job_with_no_tasks_will_return_0_on_progress_attribute() + { + $job = factory(Job::class)->create(); + + // Job progress = job tasks average progress + $this->assertEquals(0, $job->progress); + } + + /** @test */ public function a_job_has_receiveable_earning_attribute() { $job = factory(Job::class)->create(['price' => 1000]);