agregar acciones de update,delete al admin
This commit is contained in:
parent
6ee8e49b60
commit
07db23de0c
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\api;
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
|
@ -16,14 +16,14 @@
|
||||
use App\Models\Recursos;
|
||||
use App\Models\Responsables;
|
||||
|
||||
|
||||
//plan::where(["id_user" => $id_user, "id" => $id])->exists()
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
|
||||
$id_user = auth()->user()->id;
|
||||
if (plan::where(["id_user" => $id_user, "id" => $id])->exists()) {
|
||||
$id_user = auth()->user();
|
||||
if ($id_user->isCreadorPlan($id) or $id_user->isAdmin()) {
|
||||
//Actualizamos los atributos propios
|
||||
$plan = plan::find($id);
|
||||
$plan->update([
|
||||
@ -315,7 +315,6 @@ public function createPlan(Request $request)
|
||||
$responsable_aux->save();
|
||||
}
|
||||
|
||||
|
||||
return response([
|
||||
"status" => 1,
|
||||
"message" => "!Plan de mejora creado exitosamente",
|
||||
@ -323,10 +322,10 @@ public function createPlan(Request $request)
|
||||
}
|
||||
|
||||
|
||||
//confirmar los datos nesesarios
|
||||
public function listPlan()
|
||||
{
|
||||
$id_user = auth()->user()->id;
|
||||
|
||||
$planAll = plan::select('plans.id', 'plans.nombre', 'plans.codigo', 'plans.avance', 'plans.estado', 'plans.id_user', 'estandars.name as estandar_name', 'users.name as user_name')
|
||||
->join('estandars', 'plans.id_estandar', '=', 'estandars.id')
|
||||
->join('users', 'plans.id_user', '=', 'users.id')
|
||||
@ -337,7 +336,6 @@ public function listPlan()
|
||||
$plan->esCreador = ($plan->id_user == $id_user) ? true : false;
|
||||
unset($plan->id_user);
|
||||
}
|
||||
|
||||
return response([
|
||||
"status" => 1,
|
||||
"message" => "!Lista de planes de mejora",
|
||||
@ -358,8 +356,8 @@ public function updatePlan(Request $request)
|
||||
"avance" => "required|integer",
|
||||
]);
|
||||
$id = $request->id;
|
||||
$id_user = auth()->user()->id;
|
||||
if (plan::where(["id_user" => $id_user, "id" => $id])->exists()) {
|
||||
$id_user = auth()->user();
|
||||
if ($id_user->isCreadorPlan($id) or $id_user->isAdmin()) {
|
||||
$plan = plan::find($id);
|
||||
$plan->nombre = $request->nombre;
|
||||
$plan->oportunidad_plan = $request->oportunidad_plan;
|
||||
@ -385,8 +383,8 @@ public function updatePlan(Request $request)
|
||||
|
||||
public function deletePlan($id)
|
||||
{
|
||||
$id_user = auth()->user()->id;
|
||||
if (plan::where(["id" => $id, "id_user" => $id_user])->exists()) {
|
||||
$id_user = auth()->user();
|
||||
if ($id_user->isCreadorPlan($id) or $id_user->isAdmin()) {
|
||||
$plan = plan::where(["id" => $id, "id_user" => $id_user])->first();
|
||||
$plan->delete();
|
||||
return response([
|
||||
|
@ -74,7 +74,7 @@ public function userProfile()
|
||||
return response()->json([
|
||||
"status" => 0,
|
||||
"message" => "Perfil de usuario",
|
||||
"data" => auth()->user()
|
||||
"data" => auth()->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -10,36 +10,49 @@
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
|
||||
protected $table ='users';
|
||||
protected $table = 'users';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'lastname',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'lastname',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
public $timestamps = false;
|
||||
public $timestamps = false;
|
||||
|
||||
public function estandars(){
|
||||
return $this->hasMany(Estandar::class,'id');
|
||||
}
|
||||
public function plans(){
|
||||
return $this->hasMany(Plan::class,'id');
|
||||
}
|
||||
public function evidencias(){
|
||||
return $this->hasMany(Evidencia::class,'id');
|
||||
}
|
||||
public function providers(){
|
||||
return $this->hasMany(Provider::class,'id_user');
|
||||
}
|
||||
public function estandars()
|
||||
{
|
||||
return $this->hasMany(Estandar::class, 'id');
|
||||
}
|
||||
public function plans()
|
||||
{
|
||||
return $this->hasMany(Plan::class, 'id');
|
||||
}
|
||||
public function evidencias()
|
||||
{
|
||||
return $this->hasMany(Evidencia::class, 'id');
|
||||
}
|
||||
public function providers()
|
||||
{
|
||||
return $this->hasMany(Provider::class, 'id_user');
|
||||
}
|
||||
|
||||
public function roles(){
|
||||
return $this->belongsToMany(role::class,'role_user','id_user', 'id_rol');
|
||||
}
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(role::class, 'role_user', 'id_user', 'id_rol');
|
||||
}
|
||||
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->roles()->where('name', 'Admin')->exists();
|
||||
}
|
||||
|
||||
public function isCreadorPlan($id_plan)
|
||||
{
|
||||
return plan::where('id', $id_plan)->where('id_user', $this->id)->exists();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user