Merge branch 'main' into #126-vacation-request-reminders
# Conflicts: # app/Domain/Actions/VacationRequest/CreateAction.php # app/Domain/Validation/Rules/DoesNotExceedLimitRule.php
This commit is contained in:
		@@ -16,6 +16,6 @@ class CalculateVacationDaysController extends Controller
 | 
			
		||||
    {
 | 
			
		||||
        $days = $calculator->calculateDays($request->from(), $request->to());
 | 
			
		||||
 | 
			
		||||
        return new JsonResponse($days->map(fn(Carbon $day) => $day->toDateString())->all());
 | 
			
		||||
        return new JsonResponse($days->map(fn(Carbon $day): string => $day->toDateString())->all());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,8 +21,8 @@ class GetAvailableVacationTypesController extends Controller
 | 
			
		||||
        $user = User::query()->find($request->get("user"));
 | 
			
		||||
 | 
			
		||||
        $types = VacationType::all()
 | 
			
		||||
            ->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->profile->employment_form))
 | 
			
		||||
            ->map(fn(VacationType $type) => [
 | 
			
		||||
            ->filter(fn(VacationType $type): bool => $configRetriever->isAvailableFor($type, $user->profile->employment_form))
 | 
			
		||||
            ->map(fn(VacationType $type): array => [
 | 
			
		||||
                "label" => $type->label(),
 | 
			
		||||
                "value" => $type->value,
 | 
			
		||||
            ])
 | 
			
		||||
 
 | 
			
		||||
@@ -7,12 +7,11 @@ namespace Toby\Infrastructure\Http\Controllers;
 | 
			
		||||
use Illuminate\Http\Request;
 | 
			
		||||
use Illuminate\Support\Carbon;
 | 
			
		||||
use Inertia\Response;
 | 
			
		||||
use Toby\Domain\Enums\VacationType;
 | 
			
		||||
use Toby\Domain\DailySummaryRetriever;
 | 
			
		||||
use Toby\Domain\UserVacationStatsRetriever;
 | 
			
		||||
use Toby\Domain\VacationRequestStatesRetriever;
 | 
			
		||||
use Toby\Domain\VacationTypeConfigRetriever;
 | 
			
		||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
 | 
			
		||||
use Toby\Eloquent\Models\Vacation;
 | 
			
		||||
use Toby\Eloquent\Models\VacationRequest;
 | 
			
		||||
use Toby\Infrastructure\Http\Resources\HolidayResource;
 | 
			
		||||
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
 | 
			
		||||
@@ -25,24 +24,14 @@ class DashboardController extends Controller
 | 
			
		||||
        YearPeriodRetriever $yearPeriodRetriever,
 | 
			
		||||
        UserVacationStatsRetriever $vacationStatsRetriever,
 | 
			
		||||
        VacationTypeConfigRetriever $configRetriever,
 | 
			
		||||
        DailySummaryRetriever $dailySummaryRetriever,
 | 
			
		||||
    ): Response {
 | 
			
		||||
        $user = $request->user();
 | 
			
		||||
        $now = Carbon::now();
 | 
			
		||||
        $yearPeriod = $yearPeriodRetriever->selected();
 | 
			
		||||
 | 
			
		||||
        $absences = Vacation::query()
 | 
			
		||||
            ->with(["user", "vacationRequest"])
 | 
			
		||||
            ->whereDate("date", $now)
 | 
			
		||||
            ->approved()
 | 
			
		||||
            ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
 | 
			
		||||
            ->get();
 | 
			
		||||
 | 
			
		||||
        $remoteDays = Vacation::query()
 | 
			
		||||
            ->with(["user", "vacationRequest"])
 | 
			
		||||
            ->whereDate("date", $now)
 | 
			
		||||
            ->approved()
 | 
			
		||||
            ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
 | 
			
		||||
            ->get();
 | 
			
		||||
        $absences = $dailySummaryRetriever->getAbsences($now);
 | 
			
		||||
        $remoteDays = $dailySummaryRetriever->getRemoteDays($now);
 | 
			
		||||
 | 
			
		||||
        if ($user->can("listAll", VacationRequest::class)) {
 | 
			
		||||
            $vacationRequests = $yearPeriod->vacationRequests()
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,8 @@ use Illuminate\Auth\Access\AuthorizationException;
 | 
			
		||||
use Illuminate\Http\Request;
 | 
			
		||||
use Inertia\Response;
 | 
			
		||||
use Symfony\Component\HttpFoundation\RedirectResponse;
 | 
			
		||||
use Toby\Domain\Notifications\KeyHasBeenGivenNotification;
 | 
			
		||||
use Toby\Domain\Notifications\KeyHasBeenTakenNotification;
 | 
			
		||||
use Toby\Eloquent\Models\Key;
 | 
			
		||||
use Toby\Eloquent\Models\User;
 | 
			
		||||
use Toby\Infrastructure\Http\Requests\GiveKeyRequest;
 | 
			
		||||
@@ -60,6 +62,8 @@ class KeysController extends Controller
 | 
			
		||||
 | 
			
		||||
        $key->save();
 | 
			
		||||
 | 
			
		||||
        $key->notify(new KeyHasBeenTakenNotification($request->user(), $previousUser));
 | 
			
		||||
 | 
			
		||||
        return redirect()
 | 
			
		||||
            ->back()
 | 
			
		||||
            ->with("success", __("Key no :number has been taken from :user.", [
 | 
			
		||||
@@ -81,6 +85,8 @@ class KeysController extends Controller
 | 
			
		||||
 | 
			
		||||
        $key->save();
 | 
			
		||||
 | 
			
		||||
        $key->notify(new KeyHasBeenGivenNotification($request->user(), $recipient));
 | 
			
		||||
 | 
			
		||||
        return redirect()
 | 
			
		||||
            ->back()
 | 
			
		||||
            ->with("success", __("Key no :number has been given to :user.", [
 | 
			
		||||
 
 | 
			
		||||
@@ -35,8 +35,10 @@ class TimesheetController extends Controller
 | 
			
		||||
 | 
			
		||||
        $types = VacationType::all()
 | 
			
		||||
            ->filter(
 | 
			
		||||
                fn(VacationType $type) => $configRetriever->isAvailableFor($type, EmploymentForm::EmploymentContract)
 | 
			
		||||
                    && $configRetriever->isVacation($type),
 | 
			
		||||
                fn(VacationType $type): bool => $configRetriever->isAvailableFor(
 | 
			
		||||
                    $type,
 | 
			
		||||
                    EmploymentForm::EmploymentContract,
 | 
			
		||||
                ) && $configRetriever->isVacation($type),
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
        $filename = "{$carbonMonth->translatedFormat("F Y")}.xlsx";
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ class VacationLimitController extends Controller
 | 
			
		||||
            ->sortBy(fn(VacationLimit $limit): string => "{$limit->user->profile->last_name} {$limit->user->profile->first_name}")
 | 
			
		||||
            ->values();
 | 
			
		||||
 | 
			
		||||
        $limitsResource = $limits->map(fn(VacationLimit $limit) => [
 | 
			
		||||
        $limitsResource = $limits->map(fn(VacationLimit $limit): array => [
 | 
			
		||||
            "id" => $limit->id,
 | 
			
		||||
            "user" => new UserResource($limit->user),
 | 
			
		||||
            "hasVacation" => $limit->hasVacation(),
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ class HandleInertiaRequests extends Middleware
 | 
			
		||||
    {
 | 
			
		||||
        $user = $request->user();
 | 
			
		||||
 | 
			
		||||
        return fn() => [
 | 
			
		||||
        return fn(): array => [
 | 
			
		||||
            "user" => $user ? new UserResource($user) : null,
 | 
			
		||||
            "can" => [
 | 
			
		||||
                "manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false,
 | 
			
		||||
@@ -45,7 +45,7 @@ class HandleInertiaRequests extends Middleware
 | 
			
		||||
 | 
			
		||||
    protected function getFlashData(Request $request): Closure
 | 
			
		||||
    {
 | 
			
		||||
        return fn() => [
 | 
			
		||||
        return fn(): array => [
 | 
			
		||||
            "success" => $request->session()->get("success"),
 | 
			
		||||
            "error" => $request->session()->get("error"),
 | 
			
		||||
            "info" => $request->session()->get("info"),
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,8 @@ class UserRequest extends FormRequest
 | 
			
		||||
            "position" => ["required"],
 | 
			
		||||
            "employmentForm" => ["required", new Enum(EmploymentForm::class)],
 | 
			
		||||
            "employmentDate" => ["required", "date_format:Y-m-d"],
 | 
			
		||||
            "birthday" => ["nullable", "date_format:Y-m-d"],
 | 
			
		||||
            "slackId" => [],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -41,6 +43,8 @@ class UserRequest extends FormRequest
 | 
			
		||||
            "position" => $this->get("position"),
 | 
			
		||||
            "employment_form" => $this->get("employmentForm"),
 | 
			
		||||
            "employment_date" => $this->get("employmentDate"),
 | 
			
		||||
            "birthday" => $this->get("birthday"),
 | 
			
		||||
            "slack_id" => $this->get("slackId"),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@ class UserFormDataResource extends JsonResource
 | 
			
		||||
            "position" => $this->profile->position,
 | 
			
		||||
            "employmentForm" => $this->profile->employment_form,
 | 
			
		||||
            "employmentDate" => $this->profile->employment_date->toDateString(),
 | 
			
		||||
            "birthday" => $this->profile->birthday?->toDateString(),
 | 
			
		||||
            "slackId" => $this->profile->slack_id,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user