diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index 293a79b3..23c928f6 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -2,10 +2,12 @@ namespace App\Http\Controllers\V3; +use App\Enums\MissionStates; use App\Exceptions\ProhibitedAction; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; use App\Models\EdarateOstani; +use App\Models\Mission; use App\Models\RoadItemsProject; use App\Models\RoadObserved; use App\Models\SafetyAndPrivacy; @@ -28,6 +30,7 @@ class NotificationController extends Controller 'roadItem' => $this->roadItemNotifications(), 'safetyAndPrivacy' => $this->safetyAndPrivacyNotifications(), 'roadObserved' => $this->roadObservedNotifications(), + 'mission' => $this->missionNotification(), ]); } @@ -185,4 +188,33 @@ class NotificationController extends Controller return $road_observations; } + + public function missionNotification(): array + { + $user = auth()->user(); + $missions = [ + 'request_portal' => Mission::query() + ->where([ + ['state_id', '=', MissionStates::REJECT_BY_TRANSPORTATION->value], + ['user_id', '=', $user->id] + ])->count(), + 'transportation' => 0, + 'control' => 0, + ]; + + if ($user->hasPermissionTo('manage-transportation-unit')) { + $missions['transportation'] = Mission::query()->where([ + ['state_id', '=', MissionStates::REQUEST_CREATED->value], + ['edare_shahri_id', '=', $user->edarate_shahri_id] + ])->count(); + } + if ($user->hasPermissionTo('manage-control-unit')) { + $missions['control'] = Mission::query()->where([ + ['state_id', '=', MissionStates::PENDING_CONFIRMATION->value], + ['edare_shahri_id', '=', $user->edarate_shahri_id] + ])->count(); + } + + return $missions; + } } diff --git a/app/Services/Cartables/Mission/ControlUnitService.php b/app/Services/Cartables/Mission/ControlUnitService.php index f116b0cb..aa559a65 100644 --- a/app/Services/Cartables/Mission/ControlUnitService.php +++ b/app/Services/Cartables/Mission/ControlUnitService.php @@ -20,7 +20,7 @@ class ControlUnitService ->whereIn('state_id', [ MissionStates::PENDING_CONFIRMATION->value, MissionStates::START_MISSION->value ]) - ->where('edare_shahri_name', '=', Auth::user()->edarate_shahri_id); + ->where('edare_shahri_id', '=', Auth::user()->edarate_shahri_id); return DataTableFacade::run( $query, diff --git a/app/Services/Cartables/Mission/TransportationUnitService.php b/app/Services/Cartables/Mission/TransportationUnitService.php index cc378f49..7c5cc186 100644 --- a/app/Services/Cartables/Mission/TransportationUnitService.php +++ b/app/Services/Cartables/Mission/TransportationUnitService.php @@ -14,7 +14,7 @@ class TransportationUnitService { $query = Mission::query() ->where('state_id', '=', MissionStates::REQUEST_CREATED->value) - ->where('edare_shahri_name', '=', Auth::user()->edarate_shahri_id); + ->where('edare_shahri_id', '=', Auth::user()->edarate_shahri_id); return DataTableFacade::run( $query,