diff --git a/app/Http/Controllers/Api/AccionesMejorasController.php b/app/Http/Controllers/Api/AccionesMejorasController.php index e6db287..fe40166 100644 --- a/app/Http/Controllers/Api/AccionesMejorasController.php +++ b/app/Http/Controllers/Api/AccionesMejorasController.php @@ -41,8 +41,8 @@ public function delete($id) { $id_user = auth()->user()->id; if(AccionesMejoras::where(["id"=>$id,"id_user"=>$id_user])->exists()){ - $plan = AccionesMejoras::where(["id"=>$id,"id_user"=>$id_user])->first(); - $plan->delete(); + $accion = AccionesMejoras::where(["id"=>$id,"id_user"=>$id_user])->first(); + $accion->delete(); return response([ "status" => 1, "message" => "!accion eliminada con éxito!", diff --git a/app/Http/Controllers/Api/CausasRaicesController.php b/app/Http/Controllers/Api/CausasRaicesController.php index addace2..746e75a 100644 --- a/app/Http/Controllers/Api/CausasRaicesController.php +++ b/app/Http/Controllers/Api/CausasRaicesController.php @@ -41,8 +41,8 @@ public function delete($id) { $id_user = auth()->user()->id; if(CausasRaices::where(["id"=>$id,"id_user"=>$id_user])->exists()){ - $plan = CausasRaices::where(["id"=>$id,"id_user"=>$id_user])->first(); - $plan->delete(); + $causa = CausasRaices::where(["id"=>$id,"id_user"=>$id_user])->first(); + $causa->delete(); return response([ "status" => 1, "message" => "!Causa eliminada con éxito!", diff --git a/app/Http/Controllers/Api/FuentesController.php b/app/Http/Controllers/Api/FuentesController.php index 859b8f9..703cb1a 100644 --- a/app/Http/Controllers/Api/FuentesController.php +++ b/app/Http/Controllers/Api/FuentesController.php @@ -41,8 +41,8 @@ public function delete($id) { $id_user = auth()->user()->id; if(Fuentes::where(["id"=>$id,"id_user"=>$id_user])->exists()){ - $plan = Fuentes::where(["id"=>$id,"id_user"=>$id_user])->first(); - $plan->delete(); + $fuente = Fuentes::where(["id"=>$id,"id_user"=>$id_user])->first(); + $fuente->delete(); return response([ "status" => 1, "message" => "!Fuente eliminada con éxito!", diff --git a/app/Http/Controllers/Api/MetasController.php b/app/Http/Controllers/Api/MetasController.php index a4db9dd..3d5a7ce 100644 --- a/app/Http/Controllers/Api/MetasController.php +++ b/app/Http/Controllers/Api/MetasController.php @@ -1,25 +1,45 @@ validate([ - "estandar_id"=> "required|integer", + "id_plan"=> "required|integer", "descripcion"=> "required", ]); - $meta = new Metas(); - $meta->estandar_id = $request->estandar_id; - $meta->descripcion = $request->descripcion; - $meta->save(); - return response()([ - "status" => 1, - "message" => "Meta creada exitosamente" - ]); + $id_user = auth()->user()->id; + if(plan::where(["id"=>$request->id_plan])->exists()){ + $plan = plan::find($request->id_plan); + if($plan->id_user == $id_user){ + $meta = new Metas(); + $meta->id_plan = $request->id_plan; + $meta->descripcion = $request->descripcion; + $meta->save(); + return response([ + "status" => 1, + "message" => "Meta creada exitosamente", + ]); + } + else{ + return response([ + "status" => 0, + "message" => "No tienes permisos para crear esta meta", + ],404); + } + } + else{ + return response([ + "status" => 0, + "message" => "No se encontro el plan", + ],404); + } } public function update(Request $request){ @@ -27,30 +47,57 @@ public function update(Request $request){ "id"=> "required|integer", "descripcion"=> "required" ]); - $meta = Metas::find($request->id); - $meta->descripcion = $request->descripcion; - $meta->save(); - return response([ - "status" => 1, - "message" => "Meta actualizada exitosamente", - ]); - } - - public function delete($id) - { + // $id_user = auth()->user()->id; - if(Metas::where(["id"=>$id,"id_user"=>$id_user])->exists()){ - $plan = Metas::where(["id"=>$id,"id_user"=>$id_user])->first(); - $plan->delete(); - return response([ - "status" => 1, - "message" => "!Meta eliminada con éxito!", - ],200); + if(Metas::where(["id"=>$request->id])->exists()){ + $meta = Metas::find($request->id); + $plan = plan::find($meta->id_plan); + if($plan->id_user == $id_user){ + $meta->descripcion = $request->descripcion; + $meta->save(); + return response([ + "status" => 1, + "message" => "Meta actualizada exitosamente", + ]); + } + else{ + return response([ + "status" => 0, + "message" => "No tienes permisos para actualizar esta meta", + ],404); + } } else{ return response([ "status" => 0, - "message" => "!No se encontro la meta o no esta autorizado", + "message" => "No se encontro la meta", + ],404); + } + } + + public function delete($id){ + $id_user = auth()->user()->id; + if(Metas::where(["id"=>$id])->exists()){ + $meta = Metas::find($id); + $plan = plan::find($meta->id_plan); + if($plan->id_user == $id_user){ + $meta->delete(); + return response([ + "status" => 1, + "message" => "Meta eliminada exitosamente", + ]); + } + else{ + return response([ + "status" => 0, + "message" => "No tienes permisos para eliminar esta meta", + ],404); + } + } + else{ + return response([ + "status" => 0, + "message" => "No se encontro la meta", ],404); } } diff --git a/app/Http/Controllers/Api/ObservacionesController.php b/app/Http/Controllers/Api/ObservacionesController.php index 4434022..5d97617 100644 --- a/app/Http/Controllers/Api/ObservacionesController.php +++ b/app/Http/Controllers/Api/ObservacionesController.php @@ -41,8 +41,8 @@ public function delete($id) { $id_user = auth()->user()->id; if(Observaciones::where(["id"=>$id,"id_user"=>$id_user])->exists()){ - $plan = Observaciones::where(["id"=>$id,"id_user"=>$id_user])->first(); - $plan->delete(); + $observacion = Observaciones::where(["id"=>$id,"id_user"=>$id_user])->first(); + $observacion->delete(); return response([ "status" => 1, "message" => "!Observacion eliminada con éxito!", diff --git a/app/Http/Controllers/Api/PlanController.php b/app/Http/Controllers/Api/PlanController.php index dd0c41b..2565bde 100644 --- a/app/Http/Controllers/Api/PlanController.php +++ b/app/Http/Controllers/Api/PlanController.php @@ -132,11 +132,18 @@ public function createPlan(Request $request){ } public function listPlan(){ - $planAll = plan::select('plans.id', 'plans.codigo','plans.avance','plans.estado','estandars.name as estandar_name','users.name as user_name') + $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') ->orderBy('id','asc') ->get(); + + foreach($planAll as $plan){ + $plan->esCreador = ($plan->id_user == $id_user)?true:false; + unset($plan->id_user); + } return response([ "status" => 1, @@ -145,12 +152,18 @@ public function listPlan(){ ]); } -/* public function updatePlan(Request $request, $id){ $id_user = auth()->user()->id; if(plan::where(["id_user"=>$id_user,"id"=>$id])->exists()){ $plan = plan::find($id); - $plan->name = isset($request->name) ? $request->name : $plan->title; + $plan->nombre = $request->nombre; + $plan->codigo = $request->codigo; + $plan->oportunidad_plan = $request->oportunidad_plan; + $plan->semestre_ejecucion = $request->semestre_ejecucion; + $plan->duracion = $request->duracion; + $plan->estado = $request->estado; + $plan->evaluacion_eficacia = $request->evaluacion_eficacia; + $plan->avance = $request->avance; $plan->save(); return response([ "status" => 1, @@ -166,7 +179,7 @@ public function updatePlan(Request $request, $id){ } } -*/ + public function deletePlan($id){ $id_user = auth()->user()->id; diff --git a/app/Http/Controllers/Api/ProblemasOportunidadesController.php b/app/Http/Controllers/Api/ProblemasOportunidadesController.php index cc5ed95..7d30191 100644 --- a/app/Http/Controllers/Api/ProblemasOportunidadesController.php +++ b/app/Http/Controllers/Api/ProblemasOportunidadesController.php @@ -41,8 +41,8 @@ public function delete($id) { $id_user = auth()->user()->id; if(ProblemasOportunidades::where(["id"=>$id,"id_user"=>$id_user])->exists()){ - $plan = ProblemasOportunidades::where(["id"=>$id,"id_user"=>$id_user])->first(); - $plan->delete(); + $problema = ProblemasOportunidades::where(["id"=>$id,"id_user"=>$id_user])->first(); + $problema->delete(); return response([ "status" => 1, "message" => "problema eliminada con éxito!", diff --git a/app/Http/Controllers/Api/RecursosController.php b/app/Http/Controllers/Api/RecursosController.php index 4f22253..9057c57 100644 --- a/app/Http/Controllers/Api/RecursosController.php +++ b/app/Http/Controllers/Api/RecursosController.php @@ -41,8 +41,8 @@ public function delete($id) { $id_user = auth()->user()->id; if(Recursos::where(["id"=>$id,"id_user"=>$id_user])->exists()){ - $plan = Recursos::where(["id"=>$id,"id_user"=>$id_user])->first(); - $plan->delete(); + $recurso = Recursos::where(["id"=>$id,"id_user"=>$id_user])->first(); + $recurso->delete(); return response([ "status" => 1, "message" => "!Recurso eliminado con éxito!", diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 528e099..0555381 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -15,7 +15,7 @@ class DatabaseSeeder extends Seeder */ public function run() { - + //Falta crear una cuenta brayan \App\Models\User::factory()->create([ "name"=>"Alexis", "lastname"=>"Arroyo", diff --git a/routes/api.php b/routes/api.php index 0a91dbd..ed568a0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -5,14 +5,14 @@ use App\Http\Controllers\Api\UserController; use App\Http\Controllers\Api\EstandarController; use App\Http\Controllers\Api\PlanController; -use App\Http\Controllers\Api\MetasController; + use App\Http\Controllers\Api\AccionesMejorasController; use App\Http\Controllers\Api\CausasRaicesController; use App\Http\Controllers\Api\FuentesController; use App\Http\Controllers\Api\ObservacionesController; use App\Http\Controllers\Api\ProblemasOportunidadesController; use App\Http\Controllers\Api\RecursosController; - +use App\Http\Controllers\Api\MetasController; Route::post('register', [UserController::class, 'register']); Route::post('login', [UserController::class, 'login']); @@ -34,7 +34,7 @@ Route::get('plan',[PlanController::class,'listPlan']); Route::get('plan/{id}',[PlanController::class,'showPlan']); Route::delete('plan/{id}',[PlanController::class,'deletePlan']); - #Route::put('/{id}',[Controller::class,'update']); + Route::put('plan/{id}',[PlanController::class,'updatePlan']); //rutas metas Route::post('meta',[MetasController::class,'create']);