change vacation request name
This commit is contained in:
parent
dc77292278
commit
4f6883b451
@ -6,10 +6,8 @@ namespace Toby\Architecture\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
use Toby\Eloquent\Observers\UserObserver;
|
||||
use Toby\Eloquent\Observers\VacationRequestObserver;
|
||||
use Toby\Eloquent\Observers\YearPeriodObserver;
|
||||
|
||||
class ObserverServiceProvider extends ServiceProvider
|
||||
@ -18,6 +16,5 @@ class ObserverServiceProvider extends ServiceProvider
|
||||
{
|
||||
User::observe(UserObserver::class);
|
||||
YearPeriod::observe(YearPeriodObserver::class);
|
||||
VacationRequest::observe(VacationRequestObserver::class);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ use Toby\Domain\States\VacationRequest\VacationRequestState;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property VacationType $type
|
||||
* @property VacationRequestState $state
|
||||
* @property Carbon $from
|
||||
@ -90,6 +91,11 @@ class VacationRequest extends Model
|
||||
->where("to", ">=", $vacationRequest->from);
|
||||
}
|
||||
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return "{$this->id}/{$this->yearPeriod->year}";
|
||||
}
|
||||
|
||||
public function hasFlowSkipped(): bool
|
||||
{
|
||||
return $this->flow_skipped;
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Observers;
|
||||
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
|
||||
class VacationRequestObserver
|
||||
{
|
||||
public function __construct(
|
||||
protected Auth $auth,
|
||||
protected Dispatcher $dispatcher,
|
||||
) {}
|
||||
|
||||
public function creating(VacationRequest $vacationRequest): void
|
||||
{
|
||||
$year = $vacationRequest->from->year;
|
||||
|
||||
$vacationRequestNumber = $vacationRequest->user->vacationRequests()
|
||||
->whereYear("from", $year)
|
||||
->count() + 1;
|
||||
|
||||
$vacationRequest->name = "{$vacationRequestNumber}/${year}";
|
||||
}
|
||||
}
|
@ -32,8 +32,10 @@ class SendVacationRequestDaysToGoogleCalendar implements ShouldQueue
|
||||
$ranges = $this->prepareRanges($days);
|
||||
|
||||
foreach ($ranges as $range) {
|
||||
$text = "{$this->vacationRequest->type->label()} - {$this->vacationRequest->user->fullName} [{$this->vacationRequest->name}]";
|
||||
|
||||
$event = Event::create([
|
||||
"name" => "{$this->vacationRequest->type->label()} - {$this->vacationRequest->user->fullName}",
|
||||
"name" => $text,
|
||||
"startDate" => Carbon::create($range["from"]),
|
||||
"endDate" => Carbon::create($range["to"])->addDay(),
|
||||
]);
|
||||
|
@ -15,7 +15,6 @@ use Toby\Eloquent\Models\YearPeriod;
|
||||
class VacationRequestFactory extends Factory
|
||||
{
|
||||
protected $model = VacationRequest::class;
|
||||
private static int $number = 1;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
@ -26,7 +25,6 @@ class VacationRequestFactory extends Factory
|
||||
"user_id" => User::factory(),
|
||||
"creator_id" => fn(array $attributes): int => $attributes["user_id"],
|
||||
"year_period_id" => YearPeriod::factory(),
|
||||
"name" => fn(array $attributes): string => $this->generateName($attributes),
|
||||
"type" => $this->faker->randomElement(VacationType::cases()),
|
||||
"state" => $this->faker->randomElement(VacationRequestStatesRetriever::all()),
|
||||
"from" => $from,
|
||||
@ -34,12 +32,4 @@ class VacationRequestFactory extends Factory
|
||||
"comment" => $this->faker->boolean ? $this->faker->paragraph() : null,
|
||||
];
|
||||
}
|
||||
|
||||
protected function generateName(array $attributes): string
|
||||
{
|
||||
$year = YearPeriod::find($attributes["year_period_id"])->year;
|
||||
$number = static::$number++;
|
||||
|
||||
return "{$number}/{$year}";
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ return new class() extends Migration {
|
||||
{
|
||||
Schema::table("vacation_requests", function (Blueprint $table): void {
|
||||
$table->json("event_ids")->nullable();
|
||||
$table->dropColumn("name");
|
||||
});
|
||||
}
|
||||
|
||||
@ -18,6 +19,7 @@ return new class() extends Migration {
|
||||
{
|
||||
Schema::table("vacation_requests", function (Blueprint $table): void {
|
||||
$table->dropColumn("event_ids");
|
||||
$table->string("name");
|
||||
});
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user