Skip to content

Commit

Permalink
UserCompanyObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnakamura committed Sep 21, 2023
1 parent 01e2ab9 commit 850ce75
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Observers/User/UserCompanyObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Bildvitta\IssSupernova\Observers\User;

use Illuminate\Support\Facades\Config;

class UserCompanyObserver
{
public function created($userCompany)
{
if (!Config::get('iss-supernova.base_uri')) {
return;
}

$userCompany->loadMissing(
'user',
);

if ($userCompany->user) {
event('eloquent.updated: App\Models\User', $userCompany->user);
}
}

public function updated($userCompany)
{
if (!Config::get('iss-supernova.base_uri')) {
return;
}

$userCompany->loadMissing(
'user',
);

if ($userCompany->user) {
event('eloquent.updated: App\Models\User', $userCompany->user);
}
}

public function deleted($user)
{
$this->updated($user);
}
}
8 changes: 8 additions & 0 deletions src/Observers/User/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function created($user)

//Supervisor
$data['supervisor_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) {
$query->where('company_id', $user->company_id);

//Usuário que tenha cargo de Supervisor
$query->whereIn('position_id', self::getSupervisorPositionsFromCompany($user->company_id)->pluck('id'));

Expand All @@ -54,6 +56,8 @@ public function created($user)

//Gerente
$data['manager_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) {
$query->where('company_id', $user->company_id);

//Usuário que tenha cargo de Gerente
$query->whereIn('position_id', self::getManagerPositionsFromCompany($user->company_id)->pluck('id'));

Expand Down Expand Up @@ -124,6 +128,8 @@ public function updated($user)

//Supervisor
$data['supervisor_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) {
$query->where('company_id', $user->company_id);

//Usuário que tenha cargo de Supervisor
$query->whereIn('position_id', self::getSupervisorPositionsFromCompany($user->company_id)->pluck('id'));

Expand All @@ -148,6 +154,8 @@ public function updated($user)

//Gerente
$data['manager_uuid'] = config('hub.model_user')::query()->whereHas('user_companies', function ($query) use ($user) {
$query->where('company_id', $user->company_id);

//Usuário que tenha cargo de Gerente
$query->whereIn('position_id', self::getManagerPositionsFromCompany($user->company_id)->pluck('id'));

Expand Down

0 comments on commit 850ce75

Please sign in to comment.