From 1d6082a5905733aca1f6cb3097d3e2f1bd48a577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Cort=C3=A9s?= Date: Tue, 20 Jul 2021 15:27:55 -0400 Subject: [PATCH] Mcuhos cambios .w. --- .../Http/Controllers/UsuariosController.php | 44 ++++++++++--------- .../Controllers/ZonasProduccionController.php | 17 +++++++ backend/app/Models/Administrador.php | 19 -------- backend/app/Models/BodegaActual.php | 3 +- backend/app/Models/BodegaEgreso.php | 2 +- backend/app/Models/BodegaIngreso.php | 2 +- backend/app/Models/BodegaMovimiento.php | 3 +- backend/app/Models/BoletaElectronica.php | 2 +- backend/app/Models/BoletaExenta.php | 2 +- backend/app/Models/Caja.php | 2 +- backend/app/Models/CanalVenta.php | 2 +- backend/app/Models/Categoria.php | 2 +- backend/app/Models/Compra.php | 2 +- backend/app/Models/CompraIngrediente.php | 2 +- backend/app/Models/Efectivo.php | 2 +- backend/app/Models/EstadoProduccion.php | 2 +- backend/app/Models/Factura.php | 2 +- backend/app/Models/Ingrediente.php | 2 +- backend/app/Models/MedioPago.php | 2 +- backend/app/Models/Mesero.php | 19 -------- backend/app/Models/Producto.php | 2 +- backend/app/Models/Productor.php | 23 ---------- backend/app/Models/Proveedor.php | 2 +- backend/app/Models/Recaudador.php | 19 -------- backend/app/Models/Receta.php | 2 +- backend/app/Models/Restaurante.php | 2 +- backend/app/Models/Sector.php | 2 +- backend/app/Models/TipoCanal.php | 2 +- backend/app/Models/Usuario.php | 17 ++----- backend/app/Models/Venta.php | 2 +- backend/app/Models/VentaProducto.php | 2 +- backend/app/Models/ZonaProduccion.php | 6 ++- backend/routes/web.php | 12 ++--- .../modifications/05-simplify-usuario.sql | 6 +++ database/selects.sql | 8 ---- 35 files changed, 85 insertions(+), 155 deletions(-) delete mode 100644 backend/app/Models/Administrador.php delete mode 100644 backend/app/Models/Mesero.php delete mode 100644 backend/app/Models/Productor.php delete mode 100644 backend/app/Models/Recaudador.php create mode 100644 database/modifications/05-simplify-usuario.sql delete mode 100644 database/selects.sql diff --git a/backend/app/Http/Controllers/UsuariosController.php b/backend/app/Http/Controllers/UsuariosController.php index 4ce0aee..c783649 100644 --- a/backend/app/Http/Controllers/UsuariosController.php +++ b/backend/app/Http/Controllers/UsuariosController.php @@ -48,16 +48,12 @@ class UsuariosController extends Controller { * Obtiene un usuario por su id */ public function get(Request $request, $id) { - if (!str_starts_with($id, 'auth0')) app(UuidService::class)->validOrFail($id); - $usuario = Usuario::findOrFail(urldecode($id)); - return response()->json($usuario); - } + if (!str_starts_with($id, 'auth0') && $id != 'me') app(UuidService::class)->validOrFail($id); - /** - * Se obtiene al usuario logeado - */ - public function getMe(Request $request) { - return response()->json($request->user); + if ($id == 'me') $usuario = $request->user; + else $usuario = Usuario::findOrFail(urldecode($id)); + + return response()->json($usuario); } /** @@ -107,7 +103,7 @@ class UsuariosController extends Controller { * Actualiza un usuario */ public function update(Request $request, $id) { - if (!str_starts_with($id, 'auth0')) app(UuidService::class)->validOrFail($id); + if (!str_starts_with($id, 'auth0') && $id != 'me') app(UuidService::class)->validOrFail($id); $this->validate($request, [ 'nombre' => 'sometimes', @@ -118,7 +114,8 @@ class UsuariosController extends Controller { 'roles.*' => ['sometimes', Rule::in(['admin', 'mesero', 'recaudador', 'productor'])], ]); - $usuario = Usuario::findOrFail(urldecode($id)); + if ($id == 'me') $usuario = $request->user; + else $usuario = Usuario::findOrFail(urldecode($id)); $metadata = []; if ($request->input('roles')) $metadata['roles'] = $request->input('roles'); @@ -149,9 +146,10 @@ class UsuariosController extends Controller { * Elimina un usuario */ public function delete(Request $request, $id) { - if (!str_starts_with($id, 'auth0')) app(UuidService::class)->validOrFail($id); + if (!str_starts_with($id, 'auth0') && $id != 'me') app(UuidService::class)->validOrFail($id); - $usuario = Usuario::findOrFail(urldecode($id)); + if ($id == 'me') $usuario = $request->user; + else $usuario = Usuario::findOrFail(urldecode($id)); $auth0 = app(Auth0Service::class); $auth0Response = $auth0->deleteUser($usuario->auth0_id); @@ -172,8 +170,10 @@ class UsuariosController extends Controller { * Obtiene los usuarios de un restaurant */ public function getRestaurantes(Request $request, $id) { - if (!str_starts_with($id, 'auth0')) app(UuidService::class)->validOrFail($id); - $usuario = Usuario::findOrFail(urldecode($id)); + if (!str_starts_with($id, 'auth0') && $id != 'me') app(UuidService::class)->validOrFail($id); + + if ($id == 'me') $usuario = $request->user; + else $usuario = Usuario::findOrFail(urldecode($id)); return response()->json($usuario->restaurantes); } @@ -182,10 +182,12 @@ class UsuariosController extends Controller { * Agrega usuario a un restaurant */ public function addToRestaurant(Request $request, $id, $restaurant) { - if (!str_starts_with($id, 'auth0')) app(UuidService::class)->validOrFail($id); + if (!str_starts_with($id, 'auth0') && $id != 'me') app(UuidService::class)->validOrFail($id); app(UuidService::class)->validOrFail($restaurant); - $usuario = Usuario::findOrFail(urldecode($id)); + if ($id == 'me') $usuario = $request->user; + else $usuario = Usuario::findOrFail(urldecode($id)); + $restaurant = Restaurante::findOrFail($restaurant); if ($usuario->restaurantes->contains($restaurant)) { @@ -204,10 +206,12 @@ class UsuariosController extends Controller { * Saca a un usuario de un restaurant */ public function removeFromRestaurant(Request $request, $id, $restaurant) { - if (!str_starts_with($id, 'auth0')) app(UuidService::class)->validOrFail($id); - app(UuidService::class)->validOrFail($restaurant); + if (!str_starts_with($id, 'auth0') && $id != 'me') app(UuidService::class)->validOrFail($id); + app(UuidService::class)->validOrFail($restaurant); + + if ($id == 'me') $usuario = $request->user; + else $usuario = Usuario::findOrFail(urldecode($id)); - $usuario = Usuario::findOrFail(urldecode($id)); $restaurant = Restaurante::findOrFail($restaurant); if (!$usuario->restaurantes->contains($restaurant)) { diff --git a/backend/app/Http/Controllers/ZonasProduccionController.php b/backend/app/Http/Controllers/ZonasProduccionController.php index ff6ca53..ea4f838 100644 --- a/backend/app/Http/Controllers/ZonasProduccionController.php +++ b/backend/app/Http/Controllers/ZonasProduccionController.php @@ -60,6 +60,23 @@ class ZonasProduccionController extends Controller { return response()->json($zonaProduccion); } + /** + * Obtiene los usuarios de una zona de produccion + */ + public function users(Request $request, $restaurante_id, $id) { + app(UuidService::class)->validOrFail($restaurante_id); + app(UuidService::class)->validOrFail($id); + + $restaurante = Restaurante::findOrFail($restaurante_id); + $zonaProduccion = ZonaProduccion::findOrFail($id); + + if($zonaProduccion->restaurante != $restaurante) { + throw new ModelNotFoundException("zona_produccion", $id); + } + + return response()->json($zonaProduccion->usuarios); + } + /** * Crea una nueva zona de produccion */ diff --git a/backend/app/Models/Administrador.php b/backend/app/Models/Administrador.php deleted file mode 100644 index 98b35c2..0000000 --- a/backend/app/Models/Administrador.php +++ /dev/null @@ -1,19 +0,0 @@ -belongsTo(Usuario::class); - } -} diff --git a/backend/app/Models/BodegaActual.php b/backend/app/Models/BodegaActual.php index e4fb8af..e07f985 100644 --- a/backend/app/Models/BodegaActual.php +++ b/backend/app/Models/BodegaActual.php @@ -8,8 +8,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; class BodegaActual extends Model { protected $table = 'bodega_actual'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; - + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function restaurante() { return $this->belongsTo(Restaurante::class); diff --git a/backend/app/Models/BodegaEgreso.php b/backend/app/Models/BodegaEgreso.php index d1bdc6a..b37b27b 100644 --- a/backend/app/Models/BodegaEgreso.php +++ b/backend/app/Models/BodegaEgreso.php @@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; class BodegaEgreso extends Model { protected $table = 'bodega_egresos'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function restaurante() { diff --git a/backend/app/Models/BodegaIngreso.php b/backend/app/Models/BodegaIngreso.php index 97db037..5f43dbe 100644 --- a/backend/app/Models/BodegaIngreso.php +++ b/backend/app/Models/BodegaIngreso.php @@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; class BodegaIngreso extends Model { protected $table = 'bodega_ingresos'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function restaurante() { diff --git a/backend/app/Models/BodegaMovimiento.php b/backend/app/Models/BodegaMovimiento.php index 64ae5f9..da77c2f 100644 --- a/backend/app/Models/BodegaMovimiento.php +++ b/backend/app/Models/BodegaMovimiento.php @@ -8,8 +8,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; class BodegaMovimiento extends Model { protected $table = 'bodega_movimientos'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; - + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function restaurante() { return $this->belongsTo(Restaurante::class); diff --git a/backend/app/Models/BoletaElectronica.php b/backend/app/Models/BoletaElectronica.php index e734eb3..b75faf6 100644 --- a/backend/app/Models/BoletaElectronica.php +++ b/backend/app/Models/BoletaElectronica.php @@ -11,7 +11,7 @@ class BoletaElectronica extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'boletas_electronicas'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function venta() { return $this->belongsTo(Venta::class); diff --git a/backend/app/Models/BoletaExenta.php b/backend/app/Models/BoletaExenta.php index 0dc3149..a74a8df 100644 --- a/backend/app/Models/BoletaExenta.php +++ b/backend/app/Models/BoletaExenta.php @@ -11,7 +11,7 @@ class BoletaExenta extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'boletas_exentas'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function venta() { return $this->belongsTo(Venta::class); diff --git a/backend/app/Models/Caja.php b/backend/app/Models/Caja.php index b0766c1..f7e2b32 100644 --- a/backend/app/Models/Caja.php +++ b/backend/app/Models/Caja.php @@ -11,7 +11,7 @@ class Caja extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'cajas'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function restaurante() { return $this->belongsTo(Restaurante::class); diff --git a/backend/app/Models/CanalVenta.php b/backend/app/Models/CanalVenta.php index e47cda0..11176f2 100644 --- a/backend/app/Models/CanalVenta.php +++ b/backend/app/Models/CanalVenta.php @@ -11,7 +11,7 @@ class CanalVenta extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'canales_venta'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'nombre', 'restaurante_id', 'sector_id', 'tipo_canal_id']; public static function findOrFail($id) { diff --git a/backend/app/Models/Categoria.php b/backend/app/Models/Categoria.php index f838576..fe6f4fd 100644 --- a/backend/app/Models/Categoria.php +++ b/backend/app/Models/Categoria.php @@ -11,7 +11,7 @@ class Categoria extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'categorias'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'nombre', 'restaurante_id']; public static function findOrFail($id) { diff --git a/backend/app/Models/Compra.php b/backend/app/Models/Compra.php index 9c6c893..e78e0c7 100644 --- a/backend/app/Models/Compra.php +++ b/backend/app/Models/Compra.php @@ -11,7 +11,7 @@ class Compra extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'compras'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = [ 'id', 'fecha_compra', 'proveedor_id', 'en_arqueo', 'restaurante_id' ]; diff --git a/backend/app/Models/CompraIngrediente.php b/backend/app/Models/CompraIngrediente.php index 90f2b3e..26f9e1f 100644 --- a/backend/app/Models/CompraIngrediente.php +++ b/backend/app/Models/CompraIngrediente.php @@ -11,7 +11,7 @@ class CompraIngrediente extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'compra_ingredientes'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'unidades', 'monto_unitario', 'compra_id', 'ingrediente_id']; public function ingrediente() { diff --git a/backend/app/Models/Efectivo.php b/backend/app/Models/Efectivo.php index 802f9bf..ed037de 100644 --- a/backend/app/Models/Efectivo.php +++ b/backend/app/Models/Efectivo.php @@ -11,7 +11,7 @@ class Efectivo extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'efectivos'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function caja() { return $this->belongsTo(Caja::class); diff --git a/backend/app/Models/EstadoProduccion.php b/backend/app/Models/EstadoProduccion.php index 721720e..44122c8 100644 --- a/backend/app/Models/EstadoProduccion.php +++ b/backend/app/Models/EstadoProduccion.php @@ -11,5 +11,5 @@ class EstadoProduccion extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'estados_produccion'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; } diff --git a/backend/app/Models/Factura.php b/backend/app/Models/Factura.php index 80f5ecf..68f989c 100644 --- a/backend/app/Models/Factura.php +++ b/backend/app/Models/Factura.php @@ -11,7 +11,7 @@ class Factura extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'facturas'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'numero', 'monto_bruto', 'compra_id']; public static function findOrFail($id) { diff --git a/backend/app/Models/Ingrediente.php b/backend/app/Models/Ingrediente.php index cb958c8..497516b 100644 --- a/backend/app/Models/Ingrediente.php +++ b/backend/app/Models/Ingrediente.php @@ -11,7 +11,7 @@ class Ingrediente extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'ingredientes'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'nombre', 'medida', 'restaurante_id']; public static function findOrFail($id) { diff --git a/backend/app/Models/MedioPago.php b/backend/app/Models/MedioPago.php index 52151dd..0b12f3e 100644 --- a/backend/app/Models/MedioPago.php +++ b/backend/app/Models/MedioPago.php @@ -11,5 +11,5 @@ class MedioPago extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'medios_pago'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; } diff --git a/backend/app/Models/Mesero.php b/backend/app/Models/Mesero.php deleted file mode 100644 index 7cbb4da..0000000 --- a/backend/app/Models/Mesero.php +++ /dev/null @@ -1,19 +0,0 @@ -belongsTo(Usuario::class); - } -} diff --git a/backend/app/Models/Producto.php b/backend/app/Models/Producto.php index 8fa10aa..2ffd88d 100644 --- a/backend/app/Models/Producto.php +++ b/backend/app/Models/Producto.php @@ -11,7 +11,7 @@ class Producto extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'productos'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = [ 'id', 'nombre', 'precio_venta', 'categoria_id', 'zona_produccion_id', 'restaurante_id' diff --git a/backend/app/Models/Productor.php b/backend/app/Models/Productor.php deleted file mode 100644 index 0c49b2a..0000000 --- a/backend/app/Models/Productor.php +++ /dev/null @@ -1,23 +0,0 @@ -belongsTo(Usuario::class); - } - - public function zonaProduccion() { - return $this->belongsTo(ZonaProduccion::class); - } -} diff --git a/backend/app/Models/Proveedor.php b/backend/app/Models/Proveedor.php index b745f41..d6631bf 100644 --- a/backend/app/Models/Proveedor.php +++ b/backend/app/Models/Proveedor.php @@ -11,7 +11,7 @@ class Proveedor extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'proveedores'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = [ 'id', 'rut', 'nombre', 'descripcion', 'direccion', 'telefono', 'restaurante_id' diff --git a/backend/app/Models/Recaudador.php b/backend/app/Models/Recaudador.php deleted file mode 100644 index 626d0cd..0000000 --- a/backend/app/Models/Recaudador.php +++ /dev/null @@ -1,19 +0,0 @@ -belongsTo(Usuario::class); - } -} diff --git a/backend/app/Models/Receta.php b/backend/app/Models/Receta.php index fee3eb3..aea1261 100644 --- a/backend/app/Models/Receta.php +++ b/backend/app/Models/Receta.php @@ -10,7 +10,7 @@ class Receta extends Model { use UuidPrimaryKey; protected $table = 'recetas'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['unidades', 'producto_id', 'ingrediente_id']; public function ingrediente() { diff --git a/backend/app/Models/Restaurante.php b/backend/app/Models/Restaurante.php index 1f16faa..83deb8d 100644 --- a/backend/app/Models/Restaurante.php +++ b/backend/app/Models/Restaurante.php @@ -13,7 +13,7 @@ class Restaurante extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'restaurantes'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'nombre']; public static function findOrFail($id) { diff --git a/backend/app/Models/Sector.php b/backend/app/Models/Sector.php index 4a7ffdc..0b2f918 100644 --- a/backend/app/Models/Sector.php +++ b/backend/app/Models/Sector.php @@ -11,7 +11,7 @@ class Sector extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'sectores'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'nombre', 'restaurante_id']; public static function findOrFail($id) { diff --git a/backend/app/Models/TipoCanal.php b/backend/app/Models/TipoCanal.php index 1d30f2c..38283a3 100644 --- a/backend/app/Models/TipoCanal.php +++ b/backend/app/Models/TipoCanal.php @@ -11,5 +11,5 @@ class TipoCanal extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'tipos_canal'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; } diff --git a/backend/app/Models/Usuario.php b/backend/app/Models/Usuario.php index 5af8ae5..e2a487f 100644 --- a/backend/app/Models/Usuario.php +++ b/backend/app/Models/Usuario.php @@ -16,7 +16,7 @@ class Usuario extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'usuarios'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'auth0_id', 'nombre']; protected $appends = ['roles']; @@ -53,21 +53,10 @@ class Usuario extends Model { return $this->belongsToMany(Restaurante::class, 'usuarios_restaurantes', 'usuario_id', 'restaurante_id'); } - public function administrador() { - return $this->hasOne(Administrador::class); + public function zonasProduccion() { + return $this->belongsToMany(ZonaProduccion::class, 'productores', 'usuario_id', 'zona_produccion_id'); } - public function recaudador() { - return $this->hasOne(Recaudador::class); - } - - public function mesero() { - return $this->hasOne(Mesero::class); - } - - public function productor() { - return $this->hasOne(Productor::class); - } public function getRolesAttribute() { $auth0Service = app(Auth0Service::class); diff --git a/backend/app/Models/Venta.php b/backend/app/Models/Venta.php index ee35578..8fcce20 100644 --- a/backend/app/Models/Venta.php +++ b/backend/app/Models/Venta.php @@ -11,7 +11,7 @@ class Venta extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'ventas'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function mesero() { return $this->belongsTo(Mesero::class); diff --git a/backend/app/Models/VentaProducto.php b/backend/app/Models/VentaProducto.php index c24b2c1..20eb00c 100644 --- a/backend/app/Models/VentaProducto.php +++ b/backend/app/Models/VentaProducto.php @@ -11,7 +11,7 @@ class VentaProducto extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'venta_productos'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; public function venta() { return $this->belongsTo(Venta::class); diff --git a/backend/app/Models/ZonaProduccion.php b/backend/app/Models/ZonaProduccion.php index 15199aa..c98ee76 100644 --- a/backend/app/Models/ZonaProduccion.php +++ b/backend/app/Models/ZonaProduccion.php @@ -11,7 +11,7 @@ class ZonaProduccion extends Model { use UuidPrimaryKey, SoftDeletes; protected $table = 'zonas_produccion'; - protected $hidden = ['created_at', 'updated_at', 'deleted_at']; + protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot']; protected $fillable = ['id', 'nombre', 'restaurante_id']; public static function findOrFail($id) { @@ -23,4 +23,8 @@ class ZonaProduccion extends Model { public function restaurante() { return $this->belongsTo(Restaurante::class); } + + public function usuarios() { + return $this->belongsToMany(Usuario::class, 'productores', 'zona_produccion_id', 'usuario_id'); + } } diff --git a/backend/routes/web.php b/backend/routes/web.php index e8199c3..511659a 100644 --- a/backend/routes/web.php +++ b/backend/routes/web.php @@ -9,7 +9,6 @@ $router->get('/', function () use ($router) { $router->group(['prefix' => 'api/v1', 'middleware' => ['auth', 'log_endpoint']], function () use ($router) { $router->group(['prefix' => '/users'], function () use ($router) { $router->get( '/', ['as' => 'users.all', 'uses' => 'UsuariosController@all', 'middleware' => ['role:admin|global_admin']]); - $router->get( '/me', ['as' => 'users.get_me', 'uses' => 'UsuariosController@getMe']); $router->get( '/{id}', ['as' => 'users.get', 'uses' => 'UsuariosController@get', 'middleware' => ['role:admin|global_admin']]); $router->post( '/', ['as' => 'users.create', 'uses' => 'UsuariosController@create', 'middleware' => ['role:admin|global_admin']]); $router->put( '/{id}', ['as' => 'users.update', 'uses' => 'UsuariosController@update', 'middleware' => ['role:admin|global_admin']]); @@ -38,11 +37,12 @@ $router->group(['prefix' => 'api/v1', 'middleware' => ['auth', 'log_endpoint']], $router->put( '/{restaurante_id}/sectores/{id}', ['as' => 'sectores.update', 'uses' => 'SectoresController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); $router->delete('/{restaurante_id}/sectores/{id}', ['as' => 'sectores.delete', 'uses' => 'SectoresController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); - $router->get( '/{restaurante_id}/zonas-produccion', ['as' => 'zonas-produccion.all', 'uses' => 'ZonasProduccionController@all', 'middleware' => ['in_restaurante']]); - $router->get( '/{restaurante_id}/zonas-produccion/{id}', ['as' => 'zonas-produccion.get', 'uses' => 'ZonasProduccionController@get', 'middleware' => ['in_restaurante']]); - $router->post( '/{restaurante_id}/zonas-produccion', ['as' => 'zonas-produccion.create', 'uses' => 'ZonasProduccionController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); - $router->put( '/{restaurante_id}/zonas-produccion/{id}', ['as' => 'zonas-produccion.update', 'uses' => 'ZonasProduccionController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); - $router->delete('/{restaurante_id}/zonas-produccion/{id}', ['as' => 'zonas-produccion.delete', 'uses' => 'ZonasProduccionController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); + $router->get( '/{restaurante_id}/zonas-produccion', ['as' => 'zonas-produccion.all', 'uses' => 'ZonasProduccionController@all', 'middleware' => ['in_restaurante']]); + $router->get( '/{restaurante_id}/zonas-produccion/{id}', ['as' => 'zonas-produccion.get', 'uses' => 'ZonasProduccionController@get', 'middleware' => ['in_restaurante']]); + $router->get( '/{restaurante_id}/zonas-produccion/{id}/users', ['as' => 'zonas-produccion.users', 'uses' => 'ZonasProduccionController@users', 'middleware' => ['in_restaurante']]); + $router->post( '/{restaurante_id}/zonas-produccion', ['as' => 'zonas-produccion.create', 'uses' => 'ZonasProduccionController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); + $router->put( '/{restaurante_id}/zonas-produccion/{id}', ['as' => 'zonas-produccion.update', 'uses' => 'ZonasProduccionController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); + $router->delete('/{restaurante_id}/zonas-produccion/{id}', ['as' => 'zonas-produccion.delete', 'uses' => 'ZonasProduccionController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]); $router->get( '/{restaurante_id}/categorias', ['as' => 'categorias.all', 'uses' => 'CategoriasController@all', 'middleware' => ['in_restaurante']]); $router->get( '/{restaurante_id}/categorias/{id}', ['as' => 'categorias.get', 'uses' => 'CategoriasController@get', 'middleware' => ['in_restaurante']]); diff --git a/database/modifications/05-simplify-usuario.sql b/database/modifications/05-simplify-usuario.sql new file mode 100644 index 0000000..47fbdc7 --- /dev/null +++ b/database/modifications/05-simplify-usuario.sql @@ -0,0 +1,6 @@ +alter table ventas drop column mesero_id; +alter table ventas add column usuario_id uuid references usuarios; + +drop table meseros; +drop table administradores; +drop table recaudadores; \ No newline at end of file diff --git a/database/selects.sql b/database/selects.sql deleted file mode 100644 index 34559cf..0000000 --- a/database/selects.sql +++ /dev/null @@ -1,8 +0,0 @@ -select * -from bodega_ingresos; -select * -from bodega_egresos; -select * -from bodega_movimientos; -select * -from bodega_actual; \ No newline at end of file