Procházet zdrojové kódy

feat: adiciona nova logica em feriado criado por franchisor

ebagabee před 2 týdny
rodič
revize
26c40948e5

+ 14 - 0
app/Http/Controllers/HolidayController.php

@@ -34,12 +34,26 @@ public function show(int $id): JsonResponse
 
     public function update(HolidayRequest $request, int $id): JsonResponse
     {
+        $item = $this->service->findById($id);
+        if (!$item) {
+            return $this->errorResponse(message: 'Feriado não encontrado.', code: 404);
+        }
+        if ($item->base_holiday_id !== null) {
+            return $this->errorResponse(message: 'Este feriado foi criado pela franqueadora e não pode ser editado.', code: 403);
+        }
         $item = $this->service->update($id, $request->validated());
         return $this->successResponse(payload: new HolidayResource($item), message: __('messages.updated'));
     }
 
     public function destroy(int $id): JsonResponse
     {
+        $item = $this->service->findById($id);
+        if (!$item) {
+            return $this->errorResponse(message: 'Feriado não encontrado.', code: 404);
+        }
+        if ($item->base_holiday_id !== null) {
+            return $this->errorResponse(message: 'Este feriado foi criado pela franqueadora e não pode ser excluído.', code: 403);
+        }
         $this->service->delete($id);
         return $this->successResponse(message: __('messages.deleted'), code: 204);
     }

+ 8 - 7
app/Http/Resources/HolidayResource.php

@@ -12,13 +12,14 @@ class HolidayResource extends JsonResource
     public function toArray(Request $request): array
     {
         return [
-            'id'           => $this->id,
-            'unit_id'      => $this->unit_id,
-            'holiday_date' => $this->holiday_date?->format('Y-m-d'),
-            'description'  => $this->description,
-            'type'         => $this->type ?? 'feriado',
-            'created_at'   => $this->created_at?->format('Y-m-d H:i:s'),
-            'updated_at'   => $this->updated_at?->format('Y-m-d H:i:s'),
+            'id'              => $this->id,
+            'unit_id'         => $this->unit_id,
+            'base_holiday_id' => $this->base_holiday_id,
+            'holiday_date'    => $this->holiday_date?->format('Y-m-d'),
+            'description'     => $this->description,
+            'type'            => $this->type ?? 'feriado',
+            'created_at'      => $this->created_at?->format('Y-m-d H:i:s'),
+            'updated_at'      => $this->updated_at?->format('Y-m-d H:i:s'),
         ];
     }
 

+ 7 - 0
app/Services/BaseHolidayService.php

@@ -45,6 +45,13 @@ public function update(int $id, array $data): ?BaseHoliday
         }
 
         $model->update($data);
+
+        Holiday::where('base_holiday_id', $id)->update([
+            'holiday_date' => $model->holiday_date,
+            'description'  => $model->description,
+            'type'         => $model->type,
+        ]);
+
         return $model->fresh();
     }