improve code in controller and form request for V3 whit pint package
This commit is contained in:
@@ -11,7 +11,6 @@ use App\Models\Mission;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Throwable;
|
||||
@@ -22,6 +21,7 @@ class NotificationController extends Controller
|
||||
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
@@ -41,7 +41,7 @@ class NotificationController extends Controller
|
||||
{
|
||||
$user = auth()->user();
|
||||
$road_items = [
|
||||
'total' => 0
|
||||
'total' => 0,
|
||||
];
|
||||
|
||||
if ($user->hasPermissionTo('create-road-item')) {
|
||||
@@ -60,9 +60,8 @@ class NotificationController extends Controller
|
||||
->count();
|
||||
|
||||
$road_items['total'] += $road_items['supervise_cnt'];
|
||||
}
|
||||
elseif ($user->hasPermissionTo('supervise-road-item-province')) {
|
||||
throw_if(is_null($user->province_id) || !$user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
} elseif ($user->hasPermissionTo('supervise-road-item-province')) {
|
||||
throw_if(is_null($user->province_id) || ! $user->province_id, new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$road_items['supervise_cnt'] = RoadItemsProject::query()
|
||||
->where('is_new', '=', 1)
|
||||
@@ -71,20 +70,20 @@ class NotificationController extends Controller
|
||||
->count();
|
||||
|
||||
$road_items['total'] += $road_items['supervise_cnt'];
|
||||
}
|
||||
elseif ($user->hasPermissionTo('supervise-road-item-by-edareostani')) {
|
||||
throw_if(is_null($user->edarate_ostani_id) || !$user->edarate_ostani_id, new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
} elseif ($user->hasPermissionTo('supervise-road-item-by-edareostani')) {
|
||||
throw_if(is_null($user->edarate_ostani_id) || ! $user->edarate_ostani_id, new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$confirmableItems = EdarateOstani::query()->where('id', '=', $user->edarate_ostani_id)->value('items_for_confirm');
|
||||
$road_items['supervise_cnt'] = RoadItemsProject::query()
|
||||
->where('is_new', '=', 1)
|
||||
->where('province_id', '=', $user->province_id)
|
||||
->whereIn('item', explode(",", $confirmableItems))
|
||||
->whereIn('item', explode(',', $confirmableItems))
|
||||
->where('status', '=', 0)
|
||||
->count();
|
||||
|
||||
$road_items['total'] += $road_items['supervise_cnt'];
|
||||
}
|
||||
|
||||
return $road_items;
|
||||
}
|
||||
|
||||
@@ -94,15 +93,14 @@ class NotificationController extends Controller
|
||||
private function safetyAndPrivacyNotifications(): JsonResponse|array
|
||||
{
|
||||
$user = auth()->user();
|
||||
$safety_and_privacy = array();
|
||||
$safety_and_privacy = [];
|
||||
|
||||
if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) {
|
||||
$safety_and_privacy['supervise_cnt'] = SafetyAndPrivacy::query()
|
||||
->where('is_finished', '=', 1)
|
||||
->where('status', '=', 0)
|
||||
->count();
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
|
||||
} elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
|
||||
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$safety_and_privacy['supervise_cnt'] = SafetyAndPrivacy::query()
|
||||
@@ -110,8 +108,7 @@ class NotificationController extends Controller
|
||||
->where('is_finished', '=', 1)
|
||||
->where('status', '=', 0)
|
||||
->count();
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
|
||||
} elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
|
||||
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$activity = SafetyAndPrivacy::query()
|
||||
@@ -142,45 +139,43 @@ class NotificationController extends Controller
|
||||
'total' => 0,
|
||||
'operation_cnt' => 0,
|
||||
'complaint_cnt' => 0,
|
||||
'supervise_cnt' => 0
|
||||
'supervise_cnt' => 0,
|
||||
];
|
||||
|
||||
if ($user->hasPermissionTo('show-fast-react')) {
|
||||
$road_observations['supervise_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '<>', 0],
|
||||
['status', '=', 0]
|
||||
['status', '=', 0],
|
||||
])->count();
|
||||
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where('rms_status', '=', 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->count();
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-province')) {
|
||||
} elseif ($user->hasPermissionTo('show-fast-react-province')) {
|
||||
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$road_observations['supervise_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '<>', 0],
|
||||
['status', '=', 0],
|
||||
['province_id', '=', $user->province_id]
|
||||
['province_id', '=', $user->province_id],
|
||||
])->count();
|
||||
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '=', 0],
|
||||
['province_id', '=', $user->province_id]
|
||||
['province_id', '=', $user->province_id],
|
||||
])->count();
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) {
|
||||
} elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) {
|
||||
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$road_observations['operation_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '<>', 0],
|
||||
['status', '=', 2],
|
||||
['edarate_shahri_id', '=', $user->edarate_shahri_id]
|
||||
['edarate_shahri_id', '=', $user->edarate_shahri_id],
|
||||
])->count();
|
||||
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '=', 0],
|
||||
['edarate_shahri_id', '=', $user->edarate_shahri_id]
|
||||
['edarate_shahri_id', '=', $user->edarate_shahri_id],
|
||||
])->count();
|
||||
}
|
||||
|
||||
@@ -196,7 +191,7 @@ class NotificationController extends Controller
|
||||
'request_portal' => Mission::query()
|
||||
->where([
|
||||
['state_id', '=', MissionStates::REJECT_BY_TRANSPORTATION->value],
|
||||
['user_id', '=', $user->id]
|
||||
['user_id', '=', $user->id],
|
||||
])->count(),
|
||||
'transportation' => 0,
|
||||
'control' => 0,
|
||||
@@ -205,13 +200,13 @@ class NotificationController extends Controller
|
||||
if ($user->hasPermissionTo('manage-transportation-unit')) {
|
||||
$missions['transportation'] = Mission::query()->where([
|
||||
['state_id', '=', MissionStates::REQUEST_CREATED->value],
|
||||
['edare_shahri_id', '=', $user->edarate_shahri_id]
|
||||
['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]
|
||||
['edare_shahri_id', '=', $user->edarate_shahri_id],
|
||||
])->count();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user