Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AmonDeShir committed Dec 17, 2024
1 parent d034dd7 commit b1e701c
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions app/Http/Controllers/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Inertia\Inertia;
use Inertia\Response;

Expand All @@ -27,7 +25,6 @@ public function index(Quiz $quiz, SortHelper $sort, Request $request): Response
$this->authorize("invite", $quiz);

$query = User::query()->role("user")->with("school")->whereNotNull("email_verified_at");
$query = $this->groupBySchool($query, $request);
$query = $sort->sort($query, ["id"], ["name", "school"]);
$query = $this->sortByName($query, $sort);
$query = $this->sortBySchool($query, $sort);
Expand All @@ -41,23 +38,6 @@ public function index(Quiz $quiz, SortHelper $sort, Request $request): Response
]);
}

protected function groupBySchool(Builder $query, Request $request): Builder {
$groupBySchool = $request->query('groupBySchool', 'false');

if ($groupBySchool !== 'true') {
return $query;
}

$schoolIds = School::query()
->select('id')
->join('users', 'schools.id', '=', 'users.school_id')
->groupBy('schools.id')
->orderBy('schools.id')
->pluck('id');

return $query->whereIn('school_id', $schoolIds)->orderBy('school_id');
}

public function assign(Quiz $quiz, InviteQuizRequest $request, AssignToQuizAction $assignAction): RedirectResponse
{
$this->authorize("invite", $quiz);
Expand All @@ -80,6 +60,24 @@ public function unassign(Quiz $quiz, InviteQuizRequest $request, UnassignFromQui
->with("status", "Użytkownicy zostali wypisani z testu.");
}

protected function groupBySchool(Builder $query, Request $request): Builder
{
$groupBySchool = $request->query("groupBySchool", "false");

if ($groupBySchool !== "true") {
return $query;
}

$schoolIds = School::query()
->select("id")
->join("users", "schools.id", "=", "users.school_id")
->groupBy("schools.id")
->orderBy("schools.id")
->pluck("id");

return $query->whereIn("school_id", $schoolIds)->orderBy("school_id");
}

private function filterByMode(Builder $query, Request $request)
{
$mode = $request->query("mode", "user");
Expand Down

0 comments on commit b1e701c

Please sign in to comment.