Răsfoiți Sursa

fix: expose unit name in the units select endpoint

The select payload only carried `fantasy_name`, so the frontend fell back
to it and showed the trade name instead of the unit name. Return `name`
as well and order by it, falling back to `fantasy_name` when null.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TAqjSV3BQ6Q6hsfyRPiwpq
alvesantos 3 săptămâni în urmă
părinte
comite
781e9e8137

+ 3 - 1
app/Http/Controllers/SelectController.php

@@ -61,7 +61,9 @@ public function cities(): JsonResponse
 
     public function units(): JsonResponse
     {
-        return $this->items(UnitSelectResource::collection(Unit::orderBy('fantasy_name')->get()));
+        $items = Unit::orderByRaw("COALESCE(NULLIF(name, ''), fantasy_name)")->get();
+
+        return $this->items(UnitSelectResource::collection($items));
     }
 
     public function groups(): JsonResponse

+ 1 - 1
app/Http/Resources/Select/UnitSelectResource.php

@@ -9,6 +9,6 @@ class UnitSelectResource extends JsonResource
 {
     public function toArray(Request $request): array
     {
-        return ['id' => $this->id, 'fantasy_name' => $this->fantasy_name];
+        return ['id' => $this->id, 'name' => $this->name, 'fantasy_name' => $this->fantasy_name];
     }
 }