Mejoras en la api
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use App\Services\Auth0Service;
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use App\Exceptions\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\QueryException;
|
||||
@@ -38,17 +39,18 @@ class Usuario extends Model {
|
||||
* @param $id
|
||||
* @return Usuario
|
||||
*/
|
||||
public static function findByIdOrAuth0Id($id) {
|
||||
public static function findOrFail($id) {
|
||||
if (str_starts_with($id, 'auth0')) {
|
||||
return Usuario::where('auth0_id', urldecode($id))->with('restaurantes')->first();
|
||||
$usuario = Usuario::where('auth0_id', urldecode($id))->with('restaurantes')->first();
|
||||
} else {
|
||||
try {
|
||||
return Usuario::where('id', $id)->with('restaurantes')->first();
|
||||
} catch (QueryException $ex) {
|
||||
Log::warning('Se intento obtener un usuario con un id invalido', ['id' => $id]);
|
||||
return null;
|
||||
}
|
||||
$usuario = Usuario::where('id', $id)->with('restaurantes')->first();
|
||||
}
|
||||
|
||||
if(!$usuario) {
|
||||
throw new ModelNotFoundException("usuario", $id);
|
||||
}
|
||||
|
||||
return $usuario;
|
||||
}
|
||||
|
||||
public function canManageRestaurants() {
|
||||
|
||||
Reference in New Issue
Block a user