Endpoint lista de PM por usuario

master
Christian Dacid Sullca Puma 2022-10-20 02:34:46 -05:00
parent 1d342997ca
commit 356126a4aa
4 changed files with 817 additions and 877 deletions

View File

@ -6,9 +6,12 @@ use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Estandar; use App\Models\Estandar;
use App\Models\Narrativa; use App\Models\Narrativa;
//edita solo contenido //edita solo contenido
//eliminar //eliminar
// Cabecera endopoint unico // Cabecera endopoint unico
class NarrativasController extends Controller class NarrativasController extends Controller
{ {

View File

@ -17,8 +17,10 @@ use App\Models\Recursos;
use App\Models\Responsables; use App\Models\Responsables;
class PlanController extends Controller{ class PlanController extends Controller
public function update(Request $request,$id){ {
public function update(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()) {
@ -55,7 +57,8 @@ class PlanController extends Controller{
[ [
"descripcion" => $fuente['value'], "descripcion" => $fuente['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
/*----------------------------Problemas-------------------------------*/ /*----------------------------Problemas-------------------------------*/
@ -73,7 +76,8 @@ class PlanController extends Controller{
[ [
"descripcion" => $problema['value'], "descripcion" => $problema['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
/*--------------------------------Causas-------------------------------*/ /*--------------------------------Causas-------------------------------*/
@ -91,7 +95,8 @@ class PlanController extends Controller{
[ [
"descripcion" => $causa['value'], "descripcion" => $causa['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
/*------------------------------Acciones-------------------------------*/ /*------------------------------Acciones-------------------------------*/
@ -109,7 +114,8 @@ class PlanController extends Controller{
[ [
"descripcion" => $accion['value'], "descripcion" => $accion['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
/*------------------------------Recursos-------------------------------*/ /*------------------------------Recursos-------------------------------*/
@ -127,7 +133,8 @@ class PlanController extends Controller{
[ [
"descripcion" => $recurso['value'], "descripcion" => $recurso['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
/*--------------------------------Metas-------------------------------*/ /*--------------------------------Metas-------------------------------*/
@ -145,7 +152,8 @@ class PlanController extends Controller{
[ [
"descripcion" => $meta['value'], "descripcion" => $meta['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
/*---------------------------Responsables-------------------------------*/ /*---------------------------Responsables-------------------------------*/
@ -163,7 +171,8 @@ class PlanController extends Controller{
[ [
"nombre" => $responsable['value'], "nombre" => $responsable['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
/*--------------------------Observaciones-------------------------------*/ /*--------------------------Observaciones-------------------------------*/
@ -181,22 +190,22 @@ class PlanController extends Controller{
[ [
"descripcion" => $observacion['value'], "descripcion" => $observacion['value'],
"id_plan" => $plan->id "id_plan" => $plan->id
]); ]
);
} }
} }
return response()->json($plan, 200); return response()->json($plan, 200);
} } else {
else{
return response([ return response([
"status" => 0, "status" => 0,
"message" => "!No se encontro el plan o no esta autorizado", "message" => "!No se encontro el plan o no esta autorizado",
], 404); ], 404);
} }
} }
// Arreglar el formato de IDs // Arreglar el formato de IDs
public function createPlan(Request $request){ public function createPlan(Request $request)
{
$request->validate([ $request->validate([
"id_estandar" => "required|integer", "id_estandar" => "required|integer",
"nombre" => "present|max:255", "nombre" => "present|max:255",
@ -314,7 +323,8 @@ class PlanController extends Controller{
} }
public function listPlan(){ public function listPlan()
{
$id_user = auth()->user()->id; $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') $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')
@ -335,7 +345,8 @@ class PlanController extends Controller{
]); ]);
} }
public function updatePlan(Request $request){ public function updatePlan(Request $request)
{
$request->validate([ $request->validate([
"id" => "required|integer", "id" => "required|integer",
"nombre" => "required|max:255", "nombre" => "required|max:255",
@ -363,8 +374,7 @@ class PlanController extends Controller{
"message" => "!Plan de mejora actualizado", "message" => "!Plan de mejora actualizado",
"data" => $plan, "data" => $plan,
]); ]);
} } else {
else{
return response([ return response([
"status" => 0, "status" => 0,
"message" => "!No se encontro el plan o no esta autorizado", "message" => "!No se encontro el plan o no esta autorizado",
@ -373,7 +383,8 @@ class PlanController extends Controller{
} }
public function deletePlan($id){ public function deletePlan($id)
{
$id_user = auth()->user()->id; $id_user = auth()->user()->id;
if (plan::where(["id" => $id, "id_user" => $id_user])->exists()) { if (plan::where(["id" => $id, "id_user" => $id_user])->exists()) {
$plan = plan::where(["id" => $id, "id_user" => $id_user])->first(); $plan = plan::where(["id" => $id, "id_user" => $id_user])->first();
@ -382,8 +393,7 @@ class PlanController extends Controller{
"status" => 1, "status" => 1,
"message" => "!Plan de mejora eliminado", "message" => "!Plan de mejora eliminado",
]); ]);
} } else {
else{
return response([ return response([
"status" => 0, "status" => 0,
"message" => "!No se encontro el plan de mejora o no esta autorizado", "message" => "!No se encontro el plan de mejora o no esta autorizado",
@ -392,7 +402,8 @@ class PlanController extends Controller{
} }
//faltas completar //faltas completar
public function showPlan($id){ public function showPlan($id)
{
if (plan::where("id", $id)->exists()) { if (plan::where("id", $id)->exists()) {
$plan = plan::find($id); $plan = plan::find($id);
$plan->fuentes = Fuentes::where("id_plan", $id)->get(['id', 'descripcion as value']); $plan->fuentes = Fuentes::where("id_plan", $id)->get(['id', 'descripcion as value']);
@ -409,12 +420,35 @@ class PlanController extends Controller{
"message" => "!Plan de mejora encontrado", "message" => "!Plan de mejora encontrado",
"data" => $plan, "data" => $plan,
]); ]);
} } else {
else{
return response([ return response([
"status" => 0, "status" => 0,
"message" => "!No se encontro el plan de mejora", "message" => "!No se encontro el plan de mejora",
], 404); ], 404);
} }
} }
public function listPlanUser()
{
$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')
->where("plans.id_user", $id_user)
->orderBy('plans.id', 'asc')
->get();
if ($planAll->count() > 0) {
return response([
"status" => 1,
"message" => "!Lista de planes de mejora",
"data" => $planAll,
]);
} else {
return response([
"status" => 0,
"message" => "!No tienes planes de mejora",
"data" => [],
], 404);
}
}
} }

1044
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -57,6 +57,7 @@ Route::middleware("auth:sanctum")->group (function(){
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('plan/{id}', [PlanController::class, 'update']); Route::put('plan/{id}', [PlanController::class, 'update']);
Route::get('plans/user', [PlanController::class, 'listPlanUser']);
//Route::put('plan',[PlanController::class,'updatePlan']); //Route::put('plan',[PlanController::class,'updatePlan']);
//rutas metas //rutas metas