* #48 - postgreSQL db * #43 - vacation summary for employee (#66) * wip * wip * wip * wip * wip * wip * wip * #5 - bump dependencies * #43 - wip * #43 - add composer script * #43 - fix * #43 - fix * #43 - wip * #43 - ecs fix * #43 - cr fix * #43 - cr fix * #43 - fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> * #48 - redis stuff * #48 - user avatars using ui-avatars.com * #48 - fix * #48 - fix * Apply suggestions from code review Co-authored-by: Marcin Tracz <marcin.tracz@blumilk.pl> * #48 - cr fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Marcin Tracz <marcin.tracz@blumilk.pl>
		
			
				
	
	
		
			94 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace Database\Seeders;
 | 
						|
 | 
						|
use Illuminate\Database\Seeder;
 | 
						|
use Illuminate\Support\Carbon;
 | 
						|
use Toby\Domain\PolishHolidaysRetriever;
 | 
						|
use Toby\Domain\VacationDaysCalculator;
 | 
						|
use Toby\Eloquent\Models\User;
 | 
						|
use Toby\Eloquent\Models\VacationLimit;
 | 
						|
use Toby\Eloquent\Models\VacationRequest;
 | 
						|
use Toby\Eloquent\Models\YearPeriod;
 | 
						|
 | 
						|
class DatabaseSeeder extends Seeder
 | 
						|
{
 | 
						|
    public function run(): void
 | 
						|
    {
 | 
						|
        User::unsetEventDispatcher();
 | 
						|
        YearPeriod::unsetEventDispatcher();
 | 
						|
        VacationRequest::unsetEventDispatcher();
 | 
						|
 | 
						|
        User::factory(9)->create();
 | 
						|
        User::factory([
 | 
						|
            "email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
 | 
						|
        ])
 | 
						|
            ->create();
 | 
						|
 | 
						|
        $users = User::all();
 | 
						|
 | 
						|
        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();
 | 
						|
                }
 | 
						|
            })
 | 
						|
            ->afterCreating(function (YearPeriod $yearPeriod): void {
 | 
						|
                $polishHolidaysRetriever = new PolishHolidaysRetriever();
 | 
						|
 | 
						|
                foreach ($polishHolidaysRetriever->getForYearPeriod($yearPeriod) as $holiday) {
 | 
						|
                    $yearPeriod->holidays()->create([
 | 
						|
                        "name" => $holiday["name"],
 | 
						|
                        "date" => $holiday["date"],
 | 
						|
                    ]);
 | 
						|
                }
 | 
						|
            })
 | 
						|
            ->create();
 | 
						|
 | 
						|
        $yearPeriods = YearPeriod::all();
 | 
						|
 | 
						|
        foreach ($users as $user) {
 | 
						|
            VacationRequest::factory()
 | 
						|
                ->count(10)
 | 
						|
                ->for($user)
 | 
						|
                ->for($user, "creator")
 | 
						|
                ->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();
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |