Fix: pacakgeController store error tags

This commit is contained in:
Juan Felipe Zapata Moreno 2025-12-06 13:40:09 -06:00
parent 553752fcfc
commit 1784e3065b

View File

@ -56,7 +56,25 @@ public function store(PackageStoreRequest $request)
$statusAvailable = CatalogTagStatus::where('code', 'available')->first(); $statusAvailable = CatalogTagStatus::where('code', 'available')->first();
if (!$statusAvailable) { if (!$statusAvailable) {
throw new \Exception('No se encontró el status "available" para los tags'); throw new \Exception('No se encontró el status "Disponible" para los tags');
}
$existingTags = Tag::whereHas('package', function ($query) use ($request) {
$query->where('box_number', $request->box_number);
})
->whereBetween('folio', [$request->starting_page, $request->ending_page])
->get(['folio', 'package_id']);
if ($existingTags->isNotEmpty()) {
DB::rollBack();
return ApiResponse::BAD_REQUEST->response([
'message' => 'Ya existen tags en esta caja con folios en el rango especificado.',
'box_number' => $request->box_number,
'starting_page' => $request->starting_page,
'ending_page' => $request->ending_page,
'folios_conflictivos' => $existingTags->pluck('folio')->toArray(),
'total_folios_conflictivos' => $existingTags->count(),
]);
} }
// Crear los tags según el rango de páginas // Crear los tags según el rango de páginas