Эх сурвалжийг харах

✨ feat(privacidade): enriquecer resources de bloqueio com dados do perfil

- ClientProviderBlockResource: adicionados provider_district e provider_rating
- ProviderClientBlockResource: adicionado client_rating
- ClientProviderBlockService: reescrito getByClientId com JOINs para obter bairro e nota do prestador
- UserTypePermissionSeeder: adicionada permissão provider_client_block (bits:9) para PROVIDER

Fase: dev | Origin: ajuste-cliente
Gustavo Zanatta 4 өдөр өмнө
parent
commit
7f654b5530

+ 10 - 8
app/Http/Resources/ClientProviderBlockResource.php

@@ -10,14 +10,16 @@ class ClientProviderBlockResource extends JsonResource
     public function toArray(Request $request): array
     {
         return [
-            'id' => $this->id,
-            'client_id' => $this->client_id,
-            'provider_id' => $this->provider_id,
-            'provider_name' => $this->provider->user->name ?? null,
-            'provider_email' => $this->provider->user->email ?? null,
-            'provider_phone' => $this->provider->user->phone ?? null,
-            'created_at' => $this->created_at?->format('Y-m-d H:i'),
-            'updated_at' => $this->updated_at?->format('Y-m-d H:i'),
+            'id'               => $this->id,
+            'client_id'        => $this->client_id,
+            'provider_id'      => $this->provider_id,
+            'provider_name'    => $this->provider_name ?? $this->provider?->user?->name,
+            'provider_email'   => $this->provider_email ?? $this->provider?->user?->email,
+            'provider_phone'   => $this->provider_phone ?? $this->provider?->user?->phone,
+            'provider_district'=> $this->provider_district ?? null,
+            'provider_rating'  => $this->provider_rating ?? null,
+            'created_at'       => $this->created_at?->format('Y-m-d H:i'),
+            'updated_at'       => $this->updated_at?->format('Y-m-d H:i'),
         ];
     }
 }

+ 1 - 0
app/Http/Resources/ProviderClientBlockResource.php

@@ -16,6 +16,7 @@ class ProviderClientBlockResource extends JsonResource
             'client_name' => $this->client->user->name ?? null,
             'client_email' => $this->client->user->email ?? null,
             'client_phone' => $this->client->user->phone ?? null,
+            'client_rating' => $this->client->average_rating ?? null,
             'created_at' => $this->created_at?->format('Y-m-d H:i'),
             'updated_at' => $this->updated_at?->format('Y-m-d H:i'),
         ];

+ 21 - 3
app/Services/ClientProviderBlockService.php

@@ -9,9 +9,27 @@ class ClientProviderBlockService
 {
     public function getByClientId(int $clientId)
     {
-        return ClientProviderBlock::with(['provider.user'])
-            ->where('client_id', $clientId)
-            ->orderBy('created_at', 'desc')
+        return ClientProviderBlock::where('client_provider_blocks.client_id', $clientId)
+            ->leftJoin('providers', 'providers.id', '=', 'client_provider_blocks.provider_id')
+            ->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
+            ->leftJoin('addresses as provider_address', function ($join) {
+                $join->on('provider_address.source_id', '=', 'providers.id')
+                    ->where('provider_address.source', 'provider')
+                    ->whereNull('provider_address.deleted_at');
+            })
+            ->select(
+                'client_provider_blocks.id',
+                'client_provider_blocks.client_id',
+                'client_provider_blocks.provider_id',
+                'client_provider_blocks.created_at',
+                'client_provider_blocks.updated_at',
+                'provider_user.name as provider_name',
+                'provider_user.email as provider_email',
+                'provider_user.phone as provider_phone',
+                'providers.average_rating as provider_rating',
+                'provider_address.district as provider_district',
+            )
+            ->orderBy('client_provider_blocks.created_at', 'desc')
             ->get();
     }