* #23 - wip * #23 - wip * #23 - wip * #23 - wip * #23 - fix * #23 - ecs fix * #23 - fix * #23 - fix * #23 - cr fix
This commit is contained in:
24
database/factories/VacationLimitFactory.php
Normal file
24
database/factories/VacationLimitFactory.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Toby\Models\User;
|
||||
use Toby\Models\YearPeriod;
|
||||
|
||||
class VacationLimitFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
$hasVacation = $this->faker->boolean(75);
|
||||
|
||||
return [
|
||||
"user_id" => User::factory(),
|
||||
"year_period_id" => YearPeriod::factory(),
|
||||
"has_vacation" => $hasVacation,
|
||||
"days" => $hasVacation ? $this->faker->numberBetween(20, 26) : null,
|
||||
];
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Toby\Models\User;
|
||||
use Toby\Models\YearPeriod;
|
||||
|
||||
return new class() extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create("vacation_limits", function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
|
||||
$table->integer("days")->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists("vacation_limits");
|
||||
}
|
||||
};
|
@@ -6,23 +6,61 @@ namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Helpers\UserAvatarGenerator;
|
||||
use Toby\Models\User;
|
||||
use Toby\Models\VacationLimit;
|
||||
use Toby\Models\YearPeriod;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
public function __construct(
|
||||
protected UserAvatarGenerator $avatarGenerator,
|
||||
) {
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
User::factory(35)->create();
|
||||
User::unsetEventDispatcher();
|
||||
YearPeriod::unsetEventDispatcher();
|
||||
|
||||
User::factory(9)->create();
|
||||
User::factory([
|
||||
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
|
||||
])->create();
|
||||
|
||||
YearPeriod::factory([
|
||||
"year" => Carbon::now()->year,
|
||||
])->create();
|
||||
YearPeriod::factory([
|
||||
"year" => Carbon::now()->year + 1,
|
||||
])->create();
|
||||
$users = User::all();
|
||||
|
||||
$this->generateAvatarsForUsers($users);
|
||||
|
||||
YearPeriod::factory()
|
||||
->count(3)
|
||||
->sequence(
|
||||
[
|
||||
"year" => Carbon::now()->year - 1,
|
||||
],
|
||||
[
|
||||
"year" => Carbon::now()->year,
|
||||
],
|
||||
[
|
||||
"year" => Carbon::now()->year + 1,
|
||||
],
|
||||
)
|
||||
->afterCreating(function (YearPeriod $yearPeriod) use ($users): void {
|
||||
foreach ($users as $user) {
|
||||
VacationLimit::factory()
|
||||
->for($yearPeriod)
|
||||
->for($user)
|
||||
->create();
|
||||
}
|
||||
})
|
||||
->create();
|
||||
}
|
||||
|
||||
protected function generateAvatarsForUsers(Collection $users): void
|
||||
{
|
||||
foreach ($users as $user) {
|
||||
$user->saveAvatar($this->avatarGenerator->generateFor($user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user