#120 - fix
This commit is contained in:
parent
d6e29affdd
commit
847d929c77
31
app/Domain/Validation/Rules/VacationTypeCanBeSelected.php
Normal file
31
app/Domain/Validation/Rules/VacationTypeCanBeSelected.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Validation\Rules;
|
||||
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
|
||||
class VacationTypeCanBeSelected implements VacationRequestRule
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
) {}
|
||||
|
||||
public function check(VacationRequest $vacationRequest): bool
|
||||
{
|
||||
$employmentForm = $vacationRequest->user->profile->employment_form;
|
||||
|
||||
$availableTypes = VacationType::all()
|
||||
->filter(fn(VacationType $type) => $this->configRetriever->isAvailableFor($type, $employmentForm));
|
||||
|
||||
return $availableTypes->contains($vacationRequest->type);
|
||||
}
|
||||
|
||||
public function errorMessage(): string
|
||||
{
|
||||
return __("You cannot create vacation request of this type.");
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ use Toby\Domain\Validation\Rules\NoApprovedVacationRequestsInRange;
|
||||
use Toby\Domain\Validation\Rules\NoPendingVacationRequestInRange;
|
||||
use Toby\Domain\Validation\Rules\VacationRangeIsInTheSameYearRule;
|
||||
use Toby\Domain\Validation\Rules\VacationRequestRule;
|
||||
use Toby\Domain\Validation\Rules\VacationTypeCanBeSelected;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
|
||||
class VacationRequestValidator
|
||||
@ -19,6 +20,7 @@ class VacationRequestValidator
|
||||
protected array $rules = [
|
||||
VacationRangeIsInTheSameYearRule::class,
|
||||
MinimumOneVacationDayRule::class,
|
||||
VacationTypeCanBeSelected::class,
|
||||
DoesNotExceedLimitRule::class,
|
||||
NoPendingVacationRequestInRange::class,
|
||||
NoApprovedVacationRequestsInRange::class,
|
||||
|
@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Domain\VacationRequestStatesRetriever;
|
||||
|
||||
/**
|
||||
@ -58,4 +59,12 @@ class Vacation extends Model
|
||||
fn(Builder $query): Builder => $query->states(VacationRequestStatesRetriever::pendingStates()),
|
||||
);
|
||||
}
|
||||
|
||||
public function scopeWhereTypes(Builder $query, Collection $types): Builder
|
||||
{
|
||||
return $query->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query): Builder => $query->whereIn("type", $types),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,14 +7,16 @@ namespace Toby\Infrastructure\Http\Controllers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
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\AbsenceResource;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationResource;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
@ -22,6 +24,7 @@ class DashboardController extends Controller
|
||||
Request $request,
|
||||
YearPeriodRetriever $yearPeriodRetriever,
|
||||
UserVacationStatsRetriever $vacationStatsRetriever,
|
||||
VacationTypeConfigRetriever $configRetriever,
|
||||
): Response {
|
||||
$user = $request->user();
|
||||
$now = Carbon::now();
|
||||
@ -31,6 +34,14 @@ class DashboardController extends Controller
|
||||
->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();
|
||||
|
||||
if ($user->can("listAll", VacationRequest::class)) {
|
||||
@ -62,7 +73,8 @@ class DashboardController extends Controller
|
||||
$remaining = $limit - $used - $pending;
|
||||
|
||||
return inertia("Dashboard", [
|
||||
"absences" => AbsenceResource::collection($absences),
|
||||
"absences" => VacationResource::collection($absences),
|
||||
"remoteDays" => VacationResource::collection($remoteDays),
|
||||
"vacationRequests" => VacationRequestResource::collection($vacationRequests),
|
||||
"holidays" => HolidayResource::collection($holidays),
|
||||
"stats" => [
|
||||
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AbsenceResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"user" => new SimpleUserResource($this->user),
|
||||
"date" => $this->date->toDisplayString(),
|
||||
];
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ class VacationResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"user" => new SimpleUserResource($this->user),
|
||||
"displayDate" => $this->date->toDisplayString(),
|
||||
"date" => $this->date->toDateString(),
|
||||
];
|
||||
|
@ -15,9 +15,13 @@
|
||||
:requests="vacationRequests.data"
|
||||
/>
|
||||
<AbsenceList
|
||||
v-if="years.current.year === years.selected.year"
|
||||
v-if="years.current.year === years.selected.year && absences.data.length"
|
||||
:absences="absences.data"
|
||||
/>
|
||||
<HomeOfficeList
|
||||
v-if="years.current.year === years.selected.year && remoteDays.data.length"
|
||||
:remote-days="remoteDays.data"
|
||||
/>
|
||||
<UpcomingHolidays
|
||||
v-if="years.current.year === years.selected.year"
|
||||
:holidays="holidays.data"
|
||||
@ -30,6 +34,7 @@
|
||||
import Welcome from '@/Shared/Widgets/Welcome'
|
||||
import VacationStats from '@/Shared/Widgets/VacationStats'
|
||||
import AbsenceList from '@/Shared/Widgets/AbsenceList'
|
||||
import HomeOfficeList from '@/Shared/Widgets/HomeOfficeList'
|
||||
import UpcomingHolidays from '@/Shared/Widgets/UpcomingHolidays'
|
||||
import UserVacationRequests from '@/Shared/Widgets/UserVacationRequests'
|
||||
import PendingVacationRequests from '@/Shared/Widgets/PendingVacationRequests'
|
||||
@ -37,6 +42,7 @@ import PendingVacationRequests from '@/Shared/Widgets/PendingVacationRequests'
|
||||
defineProps({
|
||||
auth: Object,
|
||||
absences: Object,
|
||||
remoteDays: Object,
|
||||
vacationRequests: Object,
|
||||
holidays: Object,
|
||||
can: Object,
|
||||
|
@ -140,7 +140,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
@ -195,7 +195,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
|
@ -144,7 +144,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
@ -202,7 +202,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
|
@ -86,7 +86,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
@ -173,7 +173,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
|
@ -76,7 +76,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
|
@ -69,7 +69,7 @@
|
||||
|
||||
<span
|
||||
v-if="form.user === null"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
@ -98,7 +98,7 @@
|
||||
</div>
|
||||
<span
|
||||
v-if="form.user?.id === user.id"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
@ -149,7 +149,7 @@
|
||||
|
||||
<span
|
||||
v-if="selected"
|
||||
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
|
||||
>
|
||||
<CheckIcon class="w-5 h-5" />
|
||||
</span>
|
||||
|
@ -25,11 +25,6 @@
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
<li v-if="! absences.length">
|
||||
<p class="py-2">
|
||||
Brak danych
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
37
resources/js/Shared/Widgets/HomeOfficeList.vue
Normal file
37
resources/js/Shared/Widgets/HomeOfficeList.vue
Normal file
@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<section class="bg-white shadow-md">
|
||||
<div class="p-4 sm:px-6">
|
||||
<h2 class="text-lg font-medium leading-6 text-gray-900">
|
||||
Dzisiejsza praca zdalna
|
||||
</h2>
|
||||
</div>
|
||||
<div class="px-4 border-t border-gray-200 sm:px-6">
|
||||
<ul class="divide-y divide-gray-200">
|
||||
<li
|
||||
v-for="day in remoteDays"
|
||||
:key="day.user.id"
|
||||
class="flex py-4"
|
||||
>
|
||||
<img
|
||||
class="w-10 h-10 rounded-full"
|
||||
:src="day.user.avatar"
|
||||
>
|
||||
<div class="ml-3">
|
||||
<p class="text-sm font-medium text-gray-900">
|
||||
{{ day.user.name }}
|
||||
</p>
|
||||
<p class="text-sm text-gray-500">
|
||||
{{ day.user.email }}
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
remoteDays: Object,
|
||||
})
|
||||
</script>
|
@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\FeatureTestCase;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\PolishHolidaysRetriever;
|
||||
use Toby\Domain\States\VacationRequest\Approved;
|
||||
@ -17,6 +18,7 @@ use Toby\Domain\States\VacationRequest\Cancelled;
|
||||
use Toby\Domain\States\VacationRequest\Rejected;
|
||||
use Toby\Domain\States\VacationRequest\WaitingForAdministrative;
|
||||
use Toby\Domain\States\VacationRequest\WaitingForTechnical;
|
||||
use Toby\Eloquent\Models\Profile;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
@ -61,7 +63,9 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCanCreateVacationRequest(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()
|
||||
->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract]))
|
||||
->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -80,6 +84,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
"to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(),
|
||||
"comment" => "Comment for the vacation request.",
|
||||
])
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas("vacation_requests", [
|
||||
@ -96,7 +101,9 @@ class VacationRequestTest extends FeatureTestCase
|
||||
public function testUserCanCreateVacationRequestOnEmployeeBehalf(): void
|
||||
{
|
||||
$creator = User::factory()->admin()->create();
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()
|
||||
->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract]))
|
||||
->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -132,7 +139,9 @@ class VacationRequestTest extends FeatureTestCase
|
||||
public function testUserCanCreateVacationRequestOnEmployeeBehalfAndSkipAcceptanceFlow(): void
|
||||
{
|
||||
$creator = User::factory()->admin()->create();
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()
|
||||
->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract]))
|
||||
->create();
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
@ -245,7 +254,9 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeExceedsHisVacationLimit(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()
|
||||
->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract]))
|
||||
->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -327,7 +338,9 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeHasPendingVacationRequestInThisRange(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()
|
||||
->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract]))
|
||||
->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
@ -363,7 +376,9 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeHasApprovedVacationRequestInThisRange(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()
|
||||
->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract]))
|
||||
->create();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
|
Loading…
x
Reference in New Issue
Block a user