From e85a99d50eef2a07b57f0380ee6a5ce9bd092e29 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 31 May 2025 11:36:18 +0330 Subject: [PATCH] change the notification service --- .../Controllers/V3/NotificationController.php | 4 +- .../RoadObservation/OperatorService.php | 67 +++---------------- .../RoadObservation/SupervisorService.php | 9 +-- 3 files changed, 19 insertions(+), 61 deletions(-) diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index f5d3bb82..293a79b3 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -148,7 +148,9 @@ class NotificationController extends Controller ['status', '=', 0] ])->count(); - $road_observations['complaint_cnt'] = RoadObserved::query()->where('rms_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')) { throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); diff --git a/app/Services/Cartables/RoadObservation/OperatorService.php b/app/Services/Cartables/RoadObservation/OperatorService.php index bfec4b3e..49ceb9cb 100644 --- a/app/Services/Cartables/RoadObservation/OperatorService.php +++ b/app/Services/Cartables/RoadObservation/OperatorService.php @@ -2,6 +2,7 @@ namespace App\Services\Cartables\RoadObservation; +use App\Exceptions\ProhibitedAction; use App\Facades\DataTable\DataTableFacade; use App\Models\RoadObserved; use Illuminate\Http\Request; @@ -35,6 +36,9 @@ class OperatorService allowedSortings: ['*']); } + /** + * @throws \Throwable + */ public function complaintsIndex(Request $request) { $user = auth()->user(); @@ -46,33 +50,26 @@ class OperatorService if ($user->hasPermissionTo('show-fast-react')) { $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('rms_status', '=', 0) - ->whereNotNull('edarate_shahri_id') - ->selectRaw($fields); + ->whereNotNull('edarate_shahri_id'); } elseif ($user->hasPermissionTo('show-fast-react-province')) { - if (is_null($user->province_id)) { - return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); - } + throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('rms_status', '=', 0) ->whereNotNull('road_observeds.province_id') - ->where('road_observeds.province_id', '=', $user->province_id) - ->selectRaw($fields); + ->where('road_observeds.province_id', '=', $user->province_id); } elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) { - if (is_null($user->edarate_shahri_id)) { - return $this->errorResponse('اداره ای برای شما در سامانه ثبت نشده است!'); - } + throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('rms_status', '=', 0) ->whereNotNull('edarate_shahri_id') - ->where('edarate_shahri_id', '=', $user->edarate_shahri_id) - ->selectRaw($fields); + ->where('edarate_shahri_id', '=', $user->edarate_shahri_id); } @@ -80,50 +77,8 @@ class OperatorService $query, $request, allowedFilters: ['*'], - allowedSortings: ['*'] + allowedSortings: ['*'], + allowedSelects: $fields ); } - - public function reportIndex(Request $request) - { - $fromDate = $request->from_date . ' 00:00:00'; - $toDate = $request->date_to . ' 23:59:59'; - - $fields = [ - 'fk_RegisteredEventMessage', - 'road_observeds.id', - 'Title', - 'road_observeds.created_at', - 'lat', - 'lng', - 'FeatureTypeTitle', - 'Description', - 'MobileForSendEventSms', - 'road_observeds.province_id', - 'province_fa', - 'city_fa', - 'edarate_shahri.name_fa', - 'rms_last_activity_fa', - 'rms_description' - ]; - - $query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') - ->where('rms_status', "<>", 0) - ->whereNotNull('edarate_shahri_id') - ->whereBetween('road_observeds.created_at', [$fromDate, $toDate]) - ->select($fields); - - $data = DataTableFacade::run( - $query, - $request, - allowedFilters: ['*'], - allowedSortings: ['*'] - ); - - return [ - 'data' => $data, - 'fromDate' => $fromDate, - 'toDate' => $toDate, - ]; - } } \ No newline at end of file diff --git a/app/Services/Cartables/RoadObservation/SupervisorService.php b/app/Services/Cartables/RoadObservation/SupervisorService.php index 437c0d96..ade845a0 100644 --- a/app/Services/Cartables/RoadObservation/SupervisorService.php +++ b/app/Services/Cartables/RoadObservation/SupervisorService.php @@ -2,12 +2,16 @@ namespace App\Services\Cartables\RoadObservation; +use App\Exceptions\ProhibitedAction; use App\Facades\DataTable\DataTableFacade; use App\Models\RoadObserved; use Illuminate\Http\Request; class SupervisorService { + /** + * @throws \Throwable + */ public function index(Request $request) { $user = auth()->user(); @@ -27,10 +31,7 @@ class SupervisorService } elseif ($user->hasPermissionTo('show-fast-react-province')) { - if (is_null($user->province_id)) - { - return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); - } + throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!')); $query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id') ->where('road_observeds.province_id', $user->province_id)