Metas/plan actualizacion CRUD

This commit is contained in:
AlexisAH 2022-08-05 01:25:59 -05:00
parent 0445fab2dd
commit 7affbd95c6
10 changed files with 109 additions and 49 deletions

View File

@ -41,8 +41,8 @@ public function delete($id)
{ {
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if(AccionesMejoras::where(["id"=>$id,"id_user"=>$id_user])->exists()){ if(AccionesMejoras::where(["id"=>$id,"id_user"=>$id_user])->exists()){
$plan = AccionesMejoras::where(["id"=>$id,"id_user"=>$id_user])->first(); $accion = AccionesMejoras::where(["id"=>$id,"id_user"=>$id_user])->first();
$plan->delete(); $accion->delete();
return response([ return response([
"status" => 1, "status" => 1,
"message" => "!accion eliminada con éxito!", "message" => "!accion eliminada con éxito!",

View File

@ -41,8 +41,8 @@ public function delete($id)
{ {
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if(CausasRaices::where(["id"=>$id,"id_user"=>$id_user])->exists()){ if(CausasRaices::where(["id"=>$id,"id_user"=>$id_user])->exists()){
$plan = CausasRaices::where(["id"=>$id,"id_user"=>$id_user])->first(); $causa = CausasRaices::where(["id"=>$id,"id_user"=>$id_user])->first();
$plan->delete(); $causa->delete();
return response([ return response([
"status" => 1, "status" => 1,
"message" => "!Causa eliminada con éxito!", "message" => "!Causa eliminada con éxito!",

View File

@ -41,8 +41,8 @@ public function delete($id)
{ {
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if(Fuentes::where(["id"=>$id,"id_user"=>$id_user])->exists()){ if(Fuentes::where(["id"=>$id,"id_user"=>$id_user])->exists()){
$plan = Fuentes::where(["id"=>$id,"id_user"=>$id_user])->first(); $fuente = Fuentes::where(["id"=>$id,"id_user"=>$id_user])->first();
$plan->delete(); $fuente->delete();
return response([ return response([
"status" => 1, "status" => 1,
"message" => "!Fuente eliminada con éxito!", "message" => "!Fuente eliminada con éxito!",

View File

@ -1,25 +1,45 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Metas; use App\Models\Metas;
use App\Models\plan;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class MetasController extends Controller { class MetasController extends Controller {
public function create(Request $request) { public function create(Request $request) {
$request->validate([ $request->validate([
"estandar_id"=> "required|integer", "id_plan"=> "required|integer",
"descripcion"=> "required", "descripcion"=> "required",
]); ]);
$meta = new Metas(); $id_user = auth()->user()->id;
$meta->estandar_id = $request->estandar_id; if(plan::where(["id"=>$request->id_plan])->exists()){
$meta->descripcion = $request->descripcion; $plan = plan::find($request->id_plan);
$meta->save(); if($plan->id_user == $id_user){
return response()([ $meta = new Metas();
"status" => 1, $meta->id_plan = $request->id_plan;
"message" => "Meta creada exitosamente" $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){ public function update(Request $request){
@ -27,30 +47,57 @@ public function update(Request $request){
"id"=> "required|integer", "id"=> "required|integer",
"descripcion"=> "required" "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; $id_user = auth()->user()->id;
if(Metas::where(["id"=>$id,"id_user"=>$id_user])->exists()){ if(Metas::where(["id"=>$request->id])->exists()){
$plan = Metas::where(["id"=>$id,"id_user"=>$id_user])->first(); $meta = Metas::find($request->id);
$plan->delete(); $plan = plan::find($meta->id_plan);
return response([ if($plan->id_user == $id_user){
"status" => 1, $meta->descripcion = $request->descripcion;
"message" => "!Meta eliminada con éxito!", $meta->save();
],200); return response([
"status" => 1,
"message" => "Meta actualizada exitosamente",
]);
}
else{
return response([
"status" => 0,
"message" => "No tienes permisos para actualizar esta meta",
],404);
}
} }
else{ else{
return response([ return response([
"status" => 0, "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); ],404);
} }
} }

View File

@ -41,8 +41,8 @@ public function delete($id)
{ {
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if(Observaciones::where(["id"=>$id,"id_user"=>$id_user])->exists()){ if(Observaciones::where(["id"=>$id,"id_user"=>$id_user])->exists()){
$plan = Observaciones::where(["id"=>$id,"id_user"=>$id_user])->first(); $observacion = Observaciones::where(["id"=>$id,"id_user"=>$id_user])->first();
$plan->delete(); $observacion->delete();
return response([ return response([
"status" => 1, "status" => 1,
"message" => "!Observacion eliminada con éxito!", "message" => "!Observacion eliminada con éxito!",

View File

@ -132,12 +132,19 @@ public function createPlan(Request $request){
} }
public function listPlan(){ 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('estandars', 'plans.id_estandar', '=', 'estandars.id')
->join('users', 'plans.id_user', '=', 'users.id') ->join('users', 'plans.id_user', '=', 'users.id')
->orderBy('id','asc') ->orderBy('id','asc')
->get(); ->get();
foreach($planAll as $plan){
$plan->esCreador = ($plan->id_user == $id_user)?true:false;
unset($plan->id_user);
}
return response([ return response([
"status" => 1, "status" => 1,
"message" => "!Lista de planes de mejora", "message" => "!Lista de planes de mejora",
@ -145,12 +152,18 @@ public function listPlan(){
]); ]);
} }
/*
public function updatePlan(Request $request, $id){ public function updatePlan(Request $request, $id){
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if(plan::where(["id_user"=>$id_user,"id"=>$id])->exists()){ if(plan::where(["id_user"=>$id_user,"id"=>$id])->exists()){
$plan = plan::find($id); $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(); $plan->save();
return response([ return response([
"status" => 1, "status" => 1,
@ -166,7 +179,7 @@ public function updatePlan(Request $request, $id){
} }
} }
*/
public function deletePlan($id){ public function deletePlan($id){
$id_user = auth()->user()->id; $id_user = auth()->user()->id;

View File

@ -41,8 +41,8 @@ public function delete($id)
{ {
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if(ProblemasOportunidades::where(["id"=>$id,"id_user"=>$id_user])->exists()){ if(ProblemasOportunidades::where(["id"=>$id,"id_user"=>$id_user])->exists()){
$plan = ProblemasOportunidades::where(["id"=>$id,"id_user"=>$id_user])->first(); $problema = ProblemasOportunidades::where(["id"=>$id,"id_user"=>$id_user])->first();
$plan->delete(); $problema->delete();
return response([ return response([
"status" => 1, "status" => 1,
"message" => "problema eliminada con éxito!", "message" => "problema eliminada con éxito!",

View File

@ -41,8 +41,8 @@ public function delete($id)
{ {
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if(Recursos::where(["id"=>$id,"id_user"=>$id_user])->exists()){ if(Recursos::where(["id"=>$id,"id_user"=>$id_user])->exists()){
$plan = Recursos::where(["id"=>$id,"id_user"=>$id_user])->first(); $recurso = Recursos::where(["id"=>$id,"id_user"=>$id_user])->first();
$plan->delete(); $recurso->delete();
return response([ return response([
"status" => 1, "status" => 1,
"message" => "!Recurso eliminado con éxito!", "message" => "!Recurso eliminado con éxito!",

View File

@ -15,7 +15,7 @@ class DatabaseSeeder extends Seeder
*/ */
public function run() public function run()
{ {
//Falta crear una cuenta brayan
\App\Models\User::factory()->create([ \App\Models\User::factory()->create([
"name"=>"Alexis", "name"=>"Alexis",
"lastname"=>"Arroyo", "lastname"=>"Arroyo",

View File

@ -5,14 +5,14 @@
use App\Http\Controllers\Api\UserController; use App\Http\Controllers\Api\UserController;
use App\Http\Controllers\Api\EstandarController; use App\Http\Controllers\Api\EstandarController;
use App\Http\Controllers\Api\PlanController; use App\Http\Controllers\Api\PlanController;
use App\Http\Controllers\Api\MetasController;
use App\Http\Controllers\Api\AccionesMejorasController; use App\Http\Controllers\Api\AccionesMejorasController;
use App\Http\Controllers\Api\CausasRaicesController; use App\Http\Controllers\Api\CausasRaicesController;
use App\Http\Controllers\Api\FuentesController; use App\Http\Controllers\Api\FuentesController;
use App\Http\Controllers\Api\ObservacionesController; use App\Http\Controllers\Api\ObservacionesController;
use App\Http\Controllers\Api\ProblemasOportunidadesController; use App\Http\Controllers\Api\ProblemasOportunidadesController;
use App\Http\Controllers\Api\RecursosController; use App\Http\Controllers\Api\RecursosController;
use App\Http\Controllers\Api\MetasController;
Route::post('register', [UserController::class, 'register']); Route::post('register', [UserController::class, 'register']);
Route::post('login', [UserController::class, 'login']); Route::post('login', [UserController::class, 'login']);
@ -34,7 +34,7 @@
Route::get('plan',[PlanController::class,'listPlan']); Route::get('plan',[PlanController::class,'listPlan']);
Route::get('plan/{id}',[PlanController::class,'showPlan']); Route::get('plan/{id}',[PlanController::class,'showPlan']);
Route::delete('plan/{id}',[PlanController::class,'deletePlan']); Route::delete('plan/{id}',[PlanController::class,'deletePlan']);
#Route::put('/{id}',[Controller::class,'update']); Route::put('plan/{id}',[PlanController::class,'updatePlan']);
//rutas metas //rutas metas
Route::post('meta',[MetasController::class,'create']); Route::post('meta',[MetasController::class,'create']);