diff --git a/app/Http/Controllers/V1/Equipment/EquipmentInspectionController.php b/app/Http/Controllers/V1/Equipment/EquipmentInspectionController.php index 7433efe..661d6b9 100644 --- a/app/Http/Controllers/V1/Equipment/EquipmentInspectionController.php +++ b/app/Http/Controllers/V1/Equipment/EquipmentInspectionController.php @@ -84,10 +84,10 @@ public function resetInspection(Request $request): JsonResponse ); } - public function templates(int $id): JsonResponse + public function templates(Request $request, int $id): JsonResponse { return ApiResponse::handle( - fn () => $this->service->getActiveCycles($id), + fn () => $this->service->getTemplatesByEquipment($id, $request->input('cycle')), __('message.fetched') ); } diff --git a/app/Services/Equipment/EquipmentInspectionService.php b/app/Services/Equipment/EquipmentInspectionService.php index ebc5972..e56133e 100644 --- a/app/Services/Equipment/EquipmentInspectionService.php +++ b/app/Services/Equipment/EquipmentInspectionService.php @@ -365,6 +365,15 @@ public function copyTemplates(int $equipmentId, string $sourceCycle, array $targ }); } + public function getTemplatesByEquipment(int $equipmentId, ?string $cycle = null): \Illuminate\Database\Eloquent\Collection + { + return EquipmentInspectionTemplate::where('equipment_id', $equipmentId) + ->when($cycle, fn ($q) => $q->byCycle($cycle)) + ->active() + ->orderBy('sort_order') + ->get(); + } + public function getActiveCycles(int $equipmentId): array { return EquipmentInspectionTemplate::where('equipment_id', $equipmentId)