浏览代码

feat: :sparkles: feat(optimização-deshboard-cliente) esta sendo realizado a otimização dos dados que são carregados no payload

Esta sendo realizado o ajuste dos dados que são exibidos no payload do front para que não aparaeça dados senssiveis na parte do cliente

fase:dev | origin:escopo
kayo henrique 1 月之前
父节点
当前提交
7716c41937
共有 2 个文件被更改,包括 6 次插入21 次删除
  1. 2 2
      app/Models/Address.php
  2. 4 19
      app/Services/DashboardService.php

+ 2 - 2
app/Models/Address.php

@@ -41,11 +41,11 @@ class Address extends Model
 
     public function city()
     {
-        return $this->belongsTo(City::class);
+        return $this->belongsTo(City::class)->select('id');
     }
 
     public function state()
     {
-        return $this->belongsTo(State::class);
+        return $this->belongsTo(State::class)->select('id', 'name', 'code');
     }
 }

+ 4 - 19
app/Services/DashboardService.php

@@ -37,6 +37,7 @@ class DashboardService
     $address = Address::where('source', 'client')
       ->where('source_id', $cliente->id)
       ->with(['city', 'state'])
+      ->select('id', 'source', 'source_id', 'address', 'number', 'district', 'nickname', 'address_type', 'city_id', 'state_id', 'is_primary')
       ->first();
 
     $summaryInfos = [
@@ -47,10 +48,11 @@ class DashboardService
         ->count(),
     ];
 
-    $nextSchedules = Schedule::with('address:district,address,complement,number,source_id,source,id,address_type')
+    $nextSchedules = Schedule::with('address:district,address,source_id,source,id,address_type')
       ->where('schedules.client_id', $cliente->id)
       ->whereIn('schedules.status', ['accepted', 'paid'])
       ->whereDate('schedules.date', '>=', now()->toDateString())
+      ->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
       ->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
       ->leftJoin('custom_schedules', 'custom_schedules.schedule_id', '=', 'schedules.id')
       ->where('schedules.date', '>=', now()->toDateString())
@@ -102,10 +104,6 @@ class DashboardService
         'providers.id as provider_id',
         'provider_user.name as provider_name',
         'providers.average_rating',
-        'providers.daily_price_8h',
-        'providers.daily_price_6h',
-        'providers.daily_price_4h',
-        'providers.daily_price_2h',
         'provider_address.district as provider_district',
       )
       ->orderBy('client_favorite_providers.created_at', 'desc')
@@ -167,19 +165,6 @@ class DashboardService
         'schedules.provider_id',
         'provider_user.name as provider_name',
         'schedules.date',
-        DB::raw("TO_CHAR(schedules.date, 'DD \"de\" TMMonth \"de\" YYYY') as formatted_date"),
-        'schedules.start_time',
-        'schedules.end_time',
-        'schedules.period_type',
-        'schedules.address_id',
-        'schedules.status',
-        'schedules.total_amount',
-        DB::raw("(SELECT district FROM addresses WHERE source = 'provider' AND source_id = schedules.provider_id and deleted_at is null ORDER BY is_primary DESC LIMIT 1) as provider_district"),
-        DB::raw("CASE
-          WHEN (now() - schedules.created_at) < INTERVAL '1 hour' THEN CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 60), 'min')
-          WHEN (now() - schedules.created_at) < INTERVAL '1 day' THEN CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 3600), 'h')
-          ELSE CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 86400), 'd')
-        END as time_since_request"),
       )
       ->orderBy('schedules.date', 'asc')
       ->get();
@@ -459,7 +444,7 @@ class DashboardService
 
     $opportunities = $customScheduleService->getAvailableOpportunities($provider->id);
 
-    
+
 
     return [
       'headerBar' => $headerBar,