Metas/plan actualizacion CRUD
This commit is contained in:
parent
0445fab2dd
commit
7affbd95c6
@ -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!",
|
||||
|
@ -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!",
|
||||
|
@ -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!",
|
||||
|
@ -1,33 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Metas;
|
||||
use App\Models\plan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MetasController extends Controller {
|
||||
|
||||
public function create(Request $request) {
|
||||
$request->validate([
|
||||
"estandar_id"=> "required|integer",
|
||||
"id_plan"=> "required|integer",
|
||||
"descripcion"=> "required",
|
||||
]);
|
||||
$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->estandar_id = $request->estandar_id;
|
||||
$meta->id_plan = $request->id_plan;
|
||||
$meta->descripcion = $request->descripcion;
|
||||
$meta->save();
|
||||
return response()([
|
||||
return response([
|
||||
"status" => 1,
|
||||
"message" => "Meta creada exitosamente"
|
||||
"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){
|
||||
$request->validate([
|
||||
"id"=> "required|integer",
|
||||
"descripcion"=> "required"
|
||||
]);
|
||||
//
|
||||
$id_user = auth()->user()->id;
|
||||
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([
|
||||
@ -35,22 +60,44 @@ public function update(Request $request){
|
||||
"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();
|
||||
else{
|
||||
return response([
|
||||
"status" => 1,
|
||||
"message" => "!Meta eliminada con éxito!",
|
||||
],200);
|
||||
"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);
|
||||
}
|
||||
}
|
||||
|
@ -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!",
|
||||
|
@ -132,12 +132,19 @@ 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,
|
||||
"message" => "!Lista de planes de mejora",
|
||||
@ -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;
|
||||
|
@ -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!",
|
||||
|
@ -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!",
|
||||
|
@ -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",
|
||||
|
@ -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']);
|
||||
|
Loading…
Reference in New Issue
Block a user