Error en la validacion de usuario
This commit is contained in:
21
backend/app/Exceptions/InvalidUuidException.php
Normal file
21
backend/app/Exceptions/InvalidUuidException.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidUuidException extends Exception {
|
||||
|
||||
protected $uuid;
|
||||
|
||||
public function __construct($uuid) {
|
||||
$this->uuid = $uuid;
|
||||
}
|
||||
|
||||
public function render($request) {
|
||||
return response()->json([
|
||||
'error' => 'invalid_uuid',
|
||||
'message' => 'El id ' . $this->uuid . ' no es un UUID valido'
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,12 @@ class Usuario extends Model {
|
||||
* Busca un usuario o envia una excepcion si no se encuentra
|
||||
*/
|
||||
public static function findOrFail($id) {
|
||||
if (str_starts_with($id, 'auth0')) $usuario = Usuario::where('auth0_id', urldecode($id));
|
||||
else $usuario = Usuario::where('id', $id);
|
||||
if (str_starts_with($id, 'auth0')) $usuario = Usuario::where('auth0_id', urldecode($id))->first();
|
||||
else $usuario = Usuario::where('id', $id)->first();
|
||||
|
||||
if(!$usuario) throw new ModelNotFoundException("usuario", $id);
|
||||
|
||||
return $usuario->first();
|
||||
return $usuario;
|
||||
}
|
||||
|
||||
public function isGlobalAdmin() {
|
||||
|
||||
Reference in New Issue
Block a user