Mcuhos cambios .w.
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use App\Exceptions\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Administrador extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'administradores';
|
||||
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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'
|
||||
];
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use App\Exceptions\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Mesero extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'meseros';
|
||||
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use App\Exceptions\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Productor extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'productores';
|
||||
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
|
||||
public function zonaProduccion() {
|
||||
return $this->belongsTo(ZonaProduccion::class);
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use App\Exceptions\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Recaudador extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'recaudadores';
|
||||
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user