浏览代码

feat: adiciona dia recorrente

ebagabee 1 月之前
父节点
当前提交
5cdd993bc7

+ 1 - 1
app/Http/Requests/StudentContractRequest.php

@@ -21,7 +21,7 @@ public function rules(): array
             'second_weekday'           => 'sometimes|nullable|integer|min:0|max:6',
             'second_start_time'        => 'sometimes|nullable|date_format:H:i',
             'second_end_time'          => 'sometimes|nullable|date_format:H:i',
-            'due_date'                 => 'sometimes|nullable|date_format:Y-m-d',
+            'due_day'                  => 'sometimes|nullable|integer|min:1|max:31',
             'tax_register'             => 'sometimes|nullable|numeric|min:0',
             'down_payment'             => 'sometimes|nullable|numeric|min:0',
             'installments'             => 'sometimes|nullable|integer|min:1|max:12',

+ 1 - 2
app/Http/Resources/StudentContractResource.php

@@ -28,8 +28,7 @@ public function toArray(Request $request): array
             'second_weekday'          => $this->second_weekday,
             'second_start_time'       => $this->second_start_time,
             'second_end_time'         => $this->second_end_time,
-            'due_date'                => $this->due_date ? Carbon::parse($this->due_date)->format('d/m/Y') : null,
-            'recurring_day'           => $this->recurring_day,
+            'due_day'                 => $this->recurring_day,
             'tax_register'            => $this->tax_register,
             'down_payment'            => $this->down_payment,
             'installments'            => $this->installments,

+ 6 - 5
app/Services/StudentContractService.php

@@ -3,7 +3,6 @@
 namespace App\Services;
 
 use App\Models\StudentContract;
-use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Support\Facades\Storage;
 
@@ -25,9 +24,10 @@ public function findById(int $id): ?StudentContract
 
     public function create(array $data): StudentContract
     {
-        if (!empty($data['due_date'])) {
-            $data['recurring_day'] = Carbon::parse($data['due_date'])->day;
+        if (!empty($data['due_day'])) {
+            $data['recurring_day'] = (int) $data['due_day'];
         }
+        unset($data['due_day']);
 
         return StudentContract::create($data);
     }
@@ -40,9 +40,10 @@ public function update(int $id, array $data): ?StudentContract
             return null;
         }
 
-        if (!empty($data['due_date'])) {
-            $data['recurring_day'] = Carbon::parse($data['due_date'])->day;
+        if (!empty($data['due_day'])) {
+            $data['recurring_day'] = (int) $data['due_day'];
         }
+        unset($data['due_day']);
 
         $model->update($data);
         return $model->fresh();