add tests batch 20
This commit is contained in:
@@ -7,14 +7,16 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class PreferencesQueryService
|
||||
{
|
||||
public function __construct(private PreferencesOptionsService $options) {}
|
||||
public function __construct(private PreferencesOptionsService $options)
|
||||
{
|
||||
}
|
||||
|
||||
public function getForUser(int $userId): array
|
||||
{
|
||||
$row = Preferences::query()->where('user_id', $userId)->first();
|
||||
|
||||
$base = $this->options->defaultPreferences();
|
||||
if (! $row) {
|
||||
if (!$row) {
|
||||
return [
|
||||
'preferences' => $base,
|
||||
'options' => $this->optionsPayload(),
|
||||
@@ -33,12 +35,12 @@ class PreferencesQueryService
|
||||
->leftJoin('users', 'users.id', '=', 'user_preferences.user_id')
|
||||
->select('user_preferences.*', 'users.firstname', 'users.lastname', 'users.email');
|
||||
|
||||
if (! empty($filters['user_id'])) {
|
||||
if (!empty($filters['user_id'])) {
|
||||
$query->where('user_preferences.user_id', (int) $filters['user_id']);
|
||||
}
|
||||
|
||||
if (! empty($filters['q'])) {
|
||||
$term = '%'.strtolower(trim((string) $filters['q'])).'%';
|
||||
if (!empty($filters['q'])) {
|
||||
$term = '%' . strtolower(trim((string) $filters['q'])) . '%';
|
||||
$query->where(function ($q) use ($term) {
|
||||
$q->whereRaw('LOWER(users.firstname) LIKE ?', [$term])
|
||||
->orWhereRaw('LOWER(users.lastname) LIKE ?', [$term])
|
||||
@@ -51,7 +53,7 @@ class PreferencesQueryService
|
||||
$allowedSorts = ['updated_at', 'created_at', 'user_id'];
|
||||
|
||||
if (in_array($sortBy, $allowedSorts, true)) {
|
||||
$query->orderBy('user_preferences.'.$sortBy, $sortDir);
|
||||
$query->orderBy('user_preferences.' . $sortBy, $sortDir);
|
||||
} else {
|
||||
$query->orderBy('user_preferences.updated_at', 'desc');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user