Explorar o código

feat(treasury): expose launch fields and add casts

Resource returns amount, type, accounts and derived account_id; model casts launch_date, amount and is_reconciled.
ebagabee hai 1 mes
pai
achega
3dba897b5e
Modificáronse 2 ficheiros con 14 adicións e 11 borrados
  1. 11 10
      app/Http/Resources/TreasuryLaunchResource.php
  2. 3 1
      app/Models/TreasuryLaunch.php

+ 11 - 10
app/Http/Resources/TreasuryLaunchResource.php

@@ -19,18 +19,19 @@ public function toArray(Request $request): array
     {
         return [
             'id' => $this->id,
-            'name' => $this->name,
+            'unit_id' => $this->unit_id,
+            'transaction_type' => $this->transaction_type,
+            'from_account_id' => $this->from_account_id,
+            'to_account_id' => $this->to_account_id,
+            // Banco da movimentação (destino na entrada, origem na saída).
+            'account_id' => $this->transaction_type === 'entrada' ? $this->to_account_id : $this->from_account_id,
+            'description' => $this->description,
+            'amount' => (float) $this->amount,
+            'launch_date' => $this->launch_date,
+            'origin' => $this->origin,
+            'is_reconciled' => (bool) $this->is_reconciled,
             'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
             'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
-            // Add your fields here
-
-            // Conditional fields
-            // $this->mergeWhen($request->user()?->isAdmin(), [
-            //     'internal_notes' => $this->internal_notes,
-            // ]),
-
-            // Relationships
-            // 'user' => new UserResource($this->whenLoaded('user')),
         ];
     }
 

+ 3 - 1
app/Models/TreasuryLaunch.php

@@ -58,7 +58,9 @@ class TreasuryLaunch extends Model
     protected $casts = [
         'created_at' => 'datetime',
         'updated_at' => 'datetime',
-        // Add your casts here (e.g., 'is_active' => 'boolean')
+        'launch_date' => 'date:Y-m-d',
+        'amount' => 'decimal:2',
+        'is_reconciled' => 'boolean',
     ];
 
     // Relationships