* change layout * change layout * #22 - wip * wip * wip * #22 - wip * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - added some tests * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - cr fixes * #22 - cr fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
@@ -23,7 +23,7 @@ class UserFactory extends Factory
|
||||
"email" => $this->faker->unique()->safeEmail(),
|
||||
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
|
||||
"position" => $this->faker->jobTitle(),
|
||||
"role" => Role::EMPLOYEE,
|
||||
"role" => Role::Employee,
|
||||
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
|
||||
"remember_token" => Str::random(10),
|
||||
];
|
||||
|
15
database/factories/VacationFactory.php
Normal file
15
database/factories/VacationFactory.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class VacationFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Database\Factories;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
@@ -31,7 +30,6 @@ class VacationRequestFactory extends Factory
|
||||
"state" => $this->faker->randomElement(VacationRequestState::cases()),
|
||||
"from" => $from,
|
||||
"to" => $from->addDays($days),
|
||||
"estimated_days" => fn(array $attributes) => $this->estimateDays($attributes),
|
||||
"comment" => $this->faker->boolean ? $this->faker->paragraph() : null,
|
||||
];
|
||||
}
|
||||
@@ -43,11 +41,4 @@ class VacationRequestFactory extends Factory
|
||||
|
||||
return "{$number}/{$year}";
|
||||
}
|
||||
|
||||
protected function estimateDays(array $attributes): int
|
||||
{
|
||||
$period = CarbonPeriod::create($attributes["from"], $attributes["to"]);
|
||||
|
||||
return $period->count();
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ return new class() extends Migration {
|
||||
$table->string("last_name");
|
||||
$table->string("email")->unique();
|
||||
$table->string("avatar")->nullable();
|
||||
$table->string("role")->default(Role::EMPLOYEE->value);
|
||||
$table->string("role")->default(Role::Employee->value);
|
||||
$table->string("position");
|
||||
$table->string("employment_form");
|
||||
$table->date("employment_date");
|
||||
|
@@ -18,7 +18,6 @@ return new class() extends Migration {
|
||||
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
|
||||
$table->string("type");
|
||||
$table->string("state")->nullable();
|
||||
$table->integer("estimated_days");
|
||||
$table->date("from");
|
||||
$table->date("to");
|
||||
$table->text("comment")->nullable();
|
||||
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
return new class() extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create("vacations", function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(VacationRequest::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
|
||||
$table->date("date");
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists("vacations");
|
||||
}
|
||||
};
|
@@ -8,6 +8,7 @@ use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Domain\PolishHolidaysRetriever;
|
||||
use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Eloquent\Helpers\UserAvatarGenerator;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
@@ -79,6 +80,21 @@ class DatabaseSeeder extends Seeder
|
||||
->sequence(fn() => [
|
||||
"year_period_id" => $yearPeriods->random()->id,
|
||||
])
|
||||
->afterCreating(function (VacationRequest $vacationRequest): void {
|
||||
$days = app(VacationDaysCalculator::class)->calculateDays(
|
||||
$vacationRequest->yearPeriod,
|
||||
$vacationRequest->from,
|
||||
$vacationRequest->to,
|
||||
);
|
||||
|
||||
foreach ($days as $day) {
|
||||
$vacationRequest->vacations()->create([
|
||||
"date" => $day,
|
||||
"user_id" => $vacationRequest->user->id,
|
||||
"year_period_id" => $vacationRequest->yearPeriod->id,
|
||||
]);
|
||||
}
|
||||
})
|
||||
->create();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user