Explorar o código

Merge branch 'feature/DIARIA-kay-optimização-dashboard-cliente' of Softpar/sfp_api_laravel_diarista into development

zntt hai 1 mes
pai
achega
a26f148b24
Modificáronse 2 ficheiros con 6 adicións e 16 borrados
  1. 2 2
      app/Models/Address.php
  2. 4 14
      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 - 14
app/Services/DashboardService.php

@@ -38,6 +38,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 = [
@@ -48,7 +49,7 @@ 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())
@@ -104,10 +105,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')
@@ -169,19 +166,12 @@ 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"),
+        END as time_since_request")
       )
       ->orderBy('schedules.date', 'asc')
       ->get();
@@ -464,7 +454,7 @@ class DashboardService
 
     $opportunities = $customScheduleService->getAvailableOpportunities($provider->id);
 
-    
+
 
     return [
       'headerBar' => $headerBar,