Restaurantes se fija en el usuario que esta llamadno
This commit is contained in:
@@ -50,8 +50,8 @@ class RestaurantesController extends Controller {
|
||||
app(UuidService::class)->validOrFail($id);
|
||||
$restaurante = Restaurante::findOrFail($id);
|
||||
|
||||
if(!$request->user->isOnRestaurant($restaurante)){
|
||||
return ModelNotFoundException('restaurante', $restaurante->id);
|
||||
if(!$request->user->isOnRestaurante($restaurante)){
|
||||
throw new ModelNotFoundException('restaurante', $restaurante->id);
|
||||
}
|
||||
|
||||
return response()->json($restaurante);
|
||||
@@ -84,6 +84,11 @@ class RestaurantesController extends Controller {
|
||||
]);
|
||||
|
||||
$restaurant = Restaurante::findOrFail($id);
|
||||
|
||||
if(!$request->user->isOnRestaurante($restaurant)){
|
||||
throw new ModelNotFoundException('restaurante', $restaurant->id);
|
||||
}
|
||||
|
||||
$restaurant->nombre = $request->input('nombre');
|
||||
$restaurant->save();
|
||||
|
||||
@@ -98,11 +103,19 @@ class RestaurantesController extends Controller {
|
||||
|
||||
$restaurant = Restaurante::findOrFail($id);
|
||||
|
||||
if($restaurant->usuarios()->count() > 0) throw new CantDeleteHasChildException("restaurant", "usuario");
|
||||
if($restaurant->canalesVenta()->count() > 0) throw new CantDeleteHasChildException("restaurant", "canal_venta");
|
||||
if($restaurant->sectores()->count() > 0) throw new CantDeleteHasChildException("restaurant", "sector");
|
||||
if($restaurant->zonasProduccion()->count() > 0) throw new CantDeleteHasChildException("restaurant", "zona_produccion");
|
||||
if($restaurant->categorias()->count() > 0) throw new CantDeleteHasChildException("restaurant", "categoria");
|
||||
if($restaurant->canalesVenta()->count() > 0) throw new CantDeleteHasChildException("restaurant", "canal_venta");
|
||||
if($restaurant->categorias()->count() > 0) throw new CantDeleteHasChildException("restaurant", "categoria");
|
||||
if($restaurant->compras()->count() > 0) throw new CantDeleteHasChildException("restaurant", "compra");
|
||||
if($restaurant->usuarios()->count() > 0) throw new CantDeleteHasChildException("restaurant", "usuario");
|
||||
if($restaurant->sectores()->count() > 0) throw new CantDeleteHasChildException("restaurant", "sector");
|
||||
if($restaurant->zonasProduccion()->count() > 0) throw new CantDeleteHasChildException("restaurant", "zona_produccion");
|
||||
if($restaurant->proveedores()->count() > 0) throw new CantDeleteHasChildException("restaurant", "proveedor");
|
||||
if($restaurant->ingredientes()->count() > 0) throw new CantDeleteHasChildException("restaurant", "ingrediente");
|
||||
if($restaurant->productos()->count() > 0) throw new CantDeleteHasChildException("restaurant", "producto");
|
||||
if($restaurant->ventas()->count() > 0) throw new CantDeleteHasChildException("restaurant", "venta");
|
||||
if($restaurant->boletasElectronicas()->count() > 0) throw new CantDeleteHasChildException("restaurant", "boleta_electronica");
|
||||
if($restaurant->boletasExentas()->count() > 0) throw new CantDeleteHasChildException("restaurant", "boleta_exenta");
|
||||
if($restaurant->cajas()->count() > 0) throw new CantDeleteHasChildException("restaurant", "caja");
|
||||
|
||||
$restaurant->delete();
|
||||
return response()->json([], 204);
|
||||
|
||||
@@ -21,7 +21,11 @@ class UsuariosController extends Controller {
|
||||
* Obtiene de forma paginada los usuarios registrados en el backend
|
||||
*/
|
||||
public function all(Request $request) {
|
||||
$usuarios = Usuario::all();
|
||||
if($request->user->isGlobalAdmin()) {
|
||||
$usuarios = Usuario::all();
|
||||
} else {
|
||||
$usuarios = Restaurante::all()->intersect($request->user->restaurantes);
|
||||
}
|
||||
|
||||
$paginate = app(PaginatorService::class)->paginate(
|
||||
perPage: $request->input('per_page', 15),
|
||||
|
||||
Reference in New Issue
Block a user