Skip to content

Commit

Permalink
Merge pull request #3675 from ColoredCow/master
Browse files Browse the repository at this point in the history
Release 2 July
  • Loading branch information
GauravGusain98 authored Jul 2, 2024
2 parents 6d0991f + 45eb30b commit 2b7c7c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 0 additions & 1 deletion Modules/HR/Observers/EmployeeObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function created(Employee $employee)
$employee->update([
'name' => $gsuiteUser->getName()->fullName,
'joined_on' => Carbon::parse($gsuiteUser->getCreationTime())->format(config('constants.date_format')),
'designation' => $gsuiteUser->getOrganizations()[0]['title'],
]);
}
}
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function updateEmployeeDetailsFromGSuite(array $gsuiteUsers)
$user->employee->update([
'name' => $gsuiteUser->getName()->fullName,
'joined_on' => Carbon::parse($gsuiteUser->getCreationTime())->format(config('constants.date_format')),
'designation' => $gsuiteUser->getOrganizations()[0]['title'],
]);
}
}
Expand Down
25 changes: 25 additions & 0 deletions app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Observers;

use Carbon\Carbon;
use Modules\HR\Entities\Employee;
use Modules\User\Entities\User;

class UserObserver
{
/**
* Handle to the user "created" event.
*
* @param \Modules\User\Entities\User $user
* @return void
*/
public function created(User $user)
{
Employee::create([
'user_id' => $user->id,
'name' => $user->name,
'joined_on' => Carbon::today(),
]);
}
}
3 changes: 3 additions & 0 deletions app/Providers/DatabaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Providers;

use App\Observers\UserObserver;
use Illuminate\Support\ServiceProvider;
use Modules\User\Entities\User;

class DatabaseServiceProvider extends ServiceProvider
{
Expand All @@ -13,6 +15,7 @@ class DatabaseServiceProvider extends ServiceProvider
*/
public function boot()
{
User::observe(UserObserver::class);
}

/**
Expand Down

0 comments on commit 2b7c7c7

Please sign in to comment.