瀏覽代碼

feat: adiciona label para selectr de user type

ebagabee 2 周之前
父節點
當前提交
8ae239257f
共有 2 個文件被更改,包括 14 次插入10 次删除
  1. 10 0
      app/Enums/UserTypeEnum.php
  2. 4 10
      app/Http/Resources/UserTypeResource.php

+ 10 - 0
app/Enums/UserTypeEnum.php

@@ -12,4 +12,14 @@ enum UserTypeEnum: string
     case ADMIN_FRANCHISEE = 'ADMIN_FRANCHISEE';
     case USER = 'USER';
     case GUEST = 'GUEST';
+
+    public function label(): string
+    {
+        return match($this) {
+            self::ADMIN            => 'Administrador (Franqueadora)',
+            self::ADMIN_FRANCHISEE => 'Administrador (Franqueada)',
+            self::USER             => 'Usuário',
+            self::GUEST            => 'Convidado',
+        };
+    }
 }

+ 4 - 10
app/Http/Resources/UserTypeResource.php

@@ -3,25 +3,19 @@
 
 namespace App\Http\Resources;
 
+use App\Enums\UserTypeEnum;
 use Illuminate\Http\Request;
 use Illuminate\Http\Resources\Json\JsonResource;
 
 class UserTypeResource extends JsonResource
 {
-
     public function toArray(Request $request): array
     {
-        //TODO: Refactor this in the future
-
-        // The resource will return this
-        // [
-        //     'value' => 'value'
-        //     ...
-        // ]
+        $allowedTypes = [UserTypeEnum::ADMIN, UserTypeEnum::ADMIN_FRANCHISEE];
 
         $return = [];
-        foreach ($this->resource as $value) {
-            $return[$value] = $value;
+        foreach ($allowedTypes as $type) {
+            $return[$type->value] = $type->label();
         }
 
         return $return;