* #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>
This commit is contained in:
@@ -4,37 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Observers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Toby\Eloquent\Helpers\UserAvatarGenerator;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
public function __construct(
|
||||
protected UserAvatarGenerator $generator,
|
||||
protected YearPeriodRetriever $yearPeriodRetriever,
|
||||
) {}
|
||||
|
||||
public function created(User $user): void
|
||||
{
|
||||
$user->saveAvatar($this->generator->generateFor($user));
|
||||
|
||||
$user->vacationLimits()->create([
|
||||
"year_period_id" => $this->yearPeriodRetriever->current()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function updating(User $user): void
|
||||
{
|
||||
if ($user->isDirty(["first_name", "last_name"])) {
|
||||
Storage::delete($user->avatar);
|
||||
$user->avatar = $this->generator->generateFor($user);
|
||||
}
|
||||
}
|
||||
|
||||
public function forceDeleted(User $user): void
|
||||
{
|
||||
Storage::delete($user->avatar);
|
||||
}
|
||||
}
|
||||
|
@@ -5,14 +5,12 @@ declare(strict_types=1);
|
||||
namespace Toby\Eloquent\Observers;
|
||||
|
||||
use Toby\Domain\PolishHolidaysRetriever;
|
||||
use Toby\Eloquent\Helpers\UserAvatarGenerator;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class YearPeriodObserver
|
||||
{
|
||||
public function __construct(
|
||||
protected UserAvatarGenerator $generator,
|
||||
protected PolishHolidaysRetriever $polishHolidaysRetriever,
|
||||
) {}
|
||||
|
||||
|
Reference in New Issue
Block a user