Fixes for filters

This commit is contained in:
David Bomba 2023-11-02 12:06:34 +11:00
parent 076b14f0fa
commit de8efd9faa
2 changed files with 6 additions and 14 deletions

View File

@ -154,23 +154,15 @@ class UserFilters extends QueryFilters
$user = auth()->user(); $user = auth()->user();
if (in_array(self::STATUS_ACTIVE, $filters)) { if (in_array(self::STATUS_ACTIVE, $filters)) {
$query = $query->orWhereHas('company_users', function ($q) use($user){ $query->orWhereNull('deleted_at');
$q->where('company_id', $user->company()->id)->whereNull('deleted_at');
});
} }
if (in_array(self::STATUS_ARCHIVED, $filters)) { if (in_array(self::STATUS_ARCHIVED, $filters)) {
$query = $query->orWhereHas('company_users', function ($q) use($user){ $query->orWhereNotNull('deleted_at')->where('is_deleted', 0);
$q->where('company_id', $user->company()->id)->whereNotNull('deleted_at')->where('is_deleted', 0);
});
} }
if (in_array(self::STATUS_DELETED, $filters)) { if (in_array(self::STATUS_DELETED, $filters)) {
$query = $query->orWhereHas('company_users', function ($q) use($user){ $query->orWhere('is_deleted', 1);
$q->where('company_id', $user->company()->id)->where('is_deleted', 1);
});
} }
}); });
} }

View File

@ -195,7 +195,7 @@ class UserTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token, 'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword', 'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get("/api/v1/users?without={$company_token->user->hashed_id}&status=active"); ])->get("/api/v1/users?status=active&without={$company_token->user->hashed_id}");
$response->assertStatus(200); $response->assertStatus(200);
$this->assertCount(0, $response->json()['data']); $this->assertCount(0, $response->json()['data']);
@ -204,7 +204,7 @@ class UserTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token, 'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword', 'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get("/api/v1/users?without={$company_token->user->hashed_id}&status=archived"); ])->get("/api/v1/users?status=archived&without={$company_token->user->hashed_id}");
$response->assertStatus(200); $response->assertStatus(200);
$this->assertCount(1, $response->json()['data']); $this->assertCount(1, $response->json()['data']);
@ -213,7 +213,7 @@ class UserTest extends TestCase
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $company_token->token, 'X-API-TOKEN' => $company_token->token,
'X-API-PASSWORD' => 'ALongAndBriliantPassword', 'X-API-PASSWORD' => 'ALongAndBriliantPassword',
])->get("/api/v1/users?without={$company_token->user->hashed_id}&status=deleted"); ])->get("/api/v1/users?status=deleted&without={$company_token->user->hashed_id}");
$response->assertStatus(200); $response->assertStatus(200);
$this->assertCount(0, $response->json()['data']); $this->assertCount(0, $response->json()['data']);