This commit is contained in:
Adrian Hopek 2022-01-24 10:23:08 +01:00
parent 75889a16e6
commit 62fc1e1ca9
14 changed files with 51 additions and 37 deletions

View File

@ -11,8 +11,9 @@ use Toby\Http\Resources\UserResource;
class HandleInertiaRequests extends Middleware
{
public function __construct(protected YearPeriodRetriever $yearPeriodRetriever)
{
public function __construct(
protected YearPeriodRetriever $yearPeriodRetriever,
) {
}
public function share(Request $request): array

View File

@ -20,7 +20,6 @@ class VacationLimitRequest extends FormRequest
];
}
public function vacationLimits(): Collection
{
return VacationLimit::query()->find($this->collect("items")->pluck("id"));
@ -32,7 +31,7 @@ class VacationLimitRequest extends FormRequest
$item["id"] => [
"has_vacation" => $item["hasVacation"],
"days" => $item["days"],
]
],
]);
}
}

View File

@ -21,7 +21,9 @@ class UserObserver
{
$user->saveAvatar($this->generator->generateFor($user));
$user->vacationLimits()->create(["year_period_id" => $this->yearPeriodRetriever->current()->id]);
$user->vacationLimits()->create([
"year_period_id" => $this->yearPeriodRetriever->current()->id,
]);
}
public function updating(User $user): void

View File

@ -20,7 +20,9 @@ class YearPeriodObserver
$users = User::all();
foreach ($users as $user) {
$yearPeriod->vacationLimits()->updateOrCreate(["user_id" => $user->id]);
$yearPeriod->vacationLimits()->updateOrCreate([
"user_id" => $user->id,
]);
}
}
}

View File

@ -11,8 +11,9 @@ use Toby\Helpers\YearPeriodRetriever;
class SelectedYearPeriodScope implements Scope
{
public function __construct(protected YearPeriodRetriever $yearPeriodRetriever)
{
public function __construct(
protected YearPeriodRetriever $yearPeriodRetriever,
) {
}
public function apply(Builder $builder, Model $model): Builder

View File

@ -11,7 +11,7 @@ use Toby\Models\YearPeriod;
return new class() extends Migration {
public function up(): void
{
Schema::create('vacation_limits', function (Blueprint $table): void {
Schema::create("vacation_limits", function (Blueprint $table): void {
$table->id();
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
@ -23,6 +23,6 @@ return new class() extends Migration {
public function down(): void
{
Schema::dropIfExists('vacation_limits');
Schema::dropIfExists("vacation_limits");
}
};

View File

@ -14,8 +14,9 @@ use Toby\Models\YearPeriod;
class DatabaseSeeder extends Seeder
{
public function __construct(protected UserAvatarGenerator $avatarGenerator)
{
public function __construct(
protected UserAvatarGenerator $avatarGenerator,
) {
}
public function run(): void
@ -23,7 +24,7 @@ class DatabaseSeeder extends Seeder
User::unsetEventDispatcher();
YearPeriod::unsetEventDispatcher();
User::factory(14)->create();
User::factory(9)->create();
User::factory([
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
])->create();
@ -35,11 +36,17 @@ class DatabaseSeeder extends Seeder
YearPeriod::factory()
->count(3)
->sequence(
["year" => Carbon::now()->year - 1],
["year" => Carbon::now()->year],
["year" => Carbon::now()->year + 1],
[
"year" => Carbon::now()->year - 1,
],
[
"year" => Carbon::now()->year,
],
[
"year" => Carbon::now()->year + 1,
],
)
->afterCreating(function (YearPeriod $yearPeriod) use ($users) {
->afterCreating(function (YearPeriod $yearPeriod) use ($users): void {
foreach ($users as $user) {
VacationLimit::factory()
->for($yearPeriod)
@ -47,7 +54,7 @@ class DatabaseSeeder extends Seeder
->create();
}
})
->create();
->create();
}
protected function generateAvatarsForUsers(Collection $users): void

View File

@ -166,7 +166,7 @@ export default {
days: item.hasVacation ? item.days : null,
})),
}))
.put('/vacation-days', {
.put('/vacation-limits', {
preserveState: (page) => Object.keys(page.props.errors).length,
preserveScroll: true,
});

View File

@ -321,7 +321,7 @@ export default {
const navigation = [
{name: 'Strona główna', href: '/', current: true},
{name: 'Użytkownicy', href: '/users', current: false},
{name: 'Dostępne urlopy', href: '/vacation-days', current: false},
{name: 'Dostępne urlopy', href: '/vacation-limits', current: false},
{name: 'Company Directory', href: '#', current: false},
{name: 'Openings', href: '#', current: false},
];

View File

@ -26,7 +26,7 @@ class VacationLimitTest extends FeatureTestCase
->assertInertia(
fn(Assert $page) => $page
->component("VacationLimits")
->has("limits.data", 10)
->has("limits.data", 10),
);
}
@ -58,14 +58,14 @@ class VacationLimitTest extends FeatureTestCase
$this->actingAs($admin)
->put("/vacation-limits", [
"items" => $data
"items" => $data,
])
->assertRedirect();
$this->assertDatabaseHas("vacation_limits", [
"id" => $limit1->id,
"has_vacation" => true,
"days" => 25,
"id" => $limit1->id,
"has_vacation" => true,
"days" => 25,
]);
$this->assertDatabaseHas("vacation_limits", [

View File

@ -16,7 +16,9 @@ trait InteractsWithYearPeriods
public function createYearPeriod(int $year): YearPeriod
{
/** @var YearPeriod $yearPeriod */
$yearPeriod = YearPeriod::factory()->create(["year" => $year]);
$yearPeriod = YearPeriod::factory()->create([
"year" => $year,
]);
return $yearPeriod;
}
@ -28,7 +30,9 @@ trait InteractsWithYearPeriods
public function markYearPeriodAsSelected(YearPeriod $yearPeriod): void
{
$this->session([YearPeriodRetriever::SESSION_KEY => $yearPeriod->id]);
$this->session([
YearPeriodRetriever::SESSION_KEY => $yearPeriod->id,
]);
}
public function clearSelectedYearPeriod(): void

View File

@ -9,7 +9,6 @@ use Illuminate\Support\Carbon;
use Tests\TestCase;
use Tests\Traits\InteractsWithYearPeriods;
use Toby\Jobs\CheckYearPeriod;
use Toby\Models\YearPeriod;
class CheckYearPeriodTest extends TestCase
{

View File

@ -24,7 +24,7 @@ class YearPeriodRetrieverTest extends TestCase
public YearPeriod $nextYearPeriod;
public YearPeriodRetriever $yearPeriodRetriever;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
@ -64,20 +64,19 @@ class YearPeriodRetrieverTest extends TestCase
"navigation" => [
[
"year" => $this->previousYearPeriod->year,
"link" => route("year-periods.select", $this->previousYearPeriod)
"link" => route("year-periods.select", $this->previousYearPeriod),
],
[
"year" => $this->currentYearPeriod->year,
"link" => route("year-periods.select", $this->currentYearPeriod)
"link" => route("year-periods.select", $this->currentYearPeriod),
],
[
"year" => $this->nextYearPeriod->year,
"link" => route("year-periods.select", $this->nextYearPeriod)
"link" => route("year-periods.select", $this->nextYearPeriod),
],
]
],
];
$this->assertSame($expected, $this->yearPeriodRetriever->links());
}
}