#20 - vacation requests (#35)

* #20 - wip

* #20 - wip

* #20 - fix

* #20 - wip

* #20 - fix

* #20 - fix
This commit is contained in:
Adrian Hopek
2022-02-03 08:39:09 +01:00
committed by GitHub
parent f6d59f8bfb
commit 067b343f24
73 changed files with 5750 additions and 3576 deletions

View File

@@ -7,7 +7,8 @@ namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Toby\Domain\EmploymentForm;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\Role;
use Toby\Eloquent\Models\User;
class UserFactory extends Factory
@@ -21,6 +22,7 @@ class UserFactory extends Factory
"last_name" => $this->faker->lastName(),
"email" => $this->faker->unique()->safeEmail(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"role" => Role::EMPLOYEE,
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
"remember_token" => Str::random(10),
];

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Toby\Domain\Enums\VacationRequestState;
use Toby\Domain\Enums\VacationType;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\VacationRequest;
class VacationRequestFactory extends Factory
{
protected $model = VacationRequest::class;
public function definition(): array
{
$number = $this->faker->numberBetween(1, 20);
$year = $this->faker->year;
return [
"user_id" => User::factory(),
"name" => "{$number}/{$year}",
"type" => $this->faker->randomElement(VacationType::cases()),
"state" => $this->faker->randomElement(VacationRequestState::cases()),
"from" => $this->faker->date,
"to" => $this->faker->date,
"comment" => $this->faker->boolean ? $this->faker->paragraph() : null,
];
}
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Toby\Domain\Enums\Role;
return new class() extends Migration {
public function up(): void
@@ -15,6 +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("employment_form");
$table->date("employment_date");
$table->rememberToken();

View File

@@ -0,0 +1,30 @@
<?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;
return new class() extends Migration {
public function up(): void
{
Schema::create("vacation_requests", function (Blueprint $table): void {
$table->id();
$table->string("name");
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
$table->string("type");
$table->string("state")->nullable();
$table->date("from");
$table->date("to");
$table->text("comment")->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists("vacation_requests");
}
};

View File

@@ -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;
return new class() extends Migration {
public function up(): void
{
Schema::create("vacation_request_activities", function (Blueprint $table): void {
$table->id();
$table->foreignIdFor(VacationRequest::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(User::class)->nullable()->constrained()->cascadeOnDelete();
$table->string("from")->nullable();
$table->string("to");
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists("vacation_request_activities");
}
};

View File

@@ -11,6 +11,7 @@ use Toby\Domain\PolishHolidaysRetriever;
use Toby\Eloquent\Helpers\UserAvatarGenerator;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\VacationLimit;
use Toby\Eloquent\Models\VacationRequest;
use Toby\Eloquent\Models\YearPeriod;
class DatabaseSeeder extends Seeder
@@ -24,11 +25,14 @@ class DatabaseSeeder extends Seeder
{
User::unsetEventDispatcher();
YearPeriod::unsetEventDispatcher();
VacationRequest::unsetEventDispatcher();
User::factory(9)->create();
User::factory([
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
])->create();
])
->hasVacationRequests(5)
->create();
$users = User::all();