Ver Fonte

Actualizar solicitud si el workflow es modificado

Alan Garcia há 3 anos atrás
pai
commit
c46f786e5c

+ 135 - 88
app/Http/Controllers/RequestController.php

@@ -44,7 +44,7 @@ class RequestController extends Controller
         //FORM NO REQUERIDO POR EL MOMENTO
         $validator = Validator::make($request->all(), [
             'form' => 'array',
-            'id_module' => 'required|integer|exists:modules,id',
+            'id_module' => 'required|string|max:50|exists:modules,id',
             'id_user' => 'required|integer|exists:users,id',
         ]);
 
@@ -479,7 +479,6 @@ class RequestController extends Controller
         $request->workflow->tasks[$key]->status = $isCompleted ? 'Completed' : 'Canceled';
         $request->workflow->tasks[$key]->isValidated = $isCompleted;
 
-        $request->workflow->isCompleted = true;
         $request->workflow->status = $isCompleted ? 'Completed' : 'Canceled';
         $request->workflow->isStopped = false;
 
@@ -499,7 +498,6 @@ class RequestController extends Controller
             }, $request->currentTask->workflow->tasks);
 
             $request->currentTask->workflow->status = $isCompleted ? 'Completed' : 'Canceled';
-            $request->currentTask->workflow->isCompleted = $isCompleted;
         }
 
         $request->form = json_encode($request->form);
@@ -650,7 +648,6 @@ class RequestController extends Controller
         $key = array_search($lastTask->sequence, array_column($item->workflow->tasks, 'sequence'));
         $item->workflow->tasks[$key]->status =  'Completed';
         $item->workflow->tasks[$key]->isValidated =  true;
-        $item->workflow->isCompleted = true;
         $item->workflow->status =  'Completed';
 
         /** SI LA LISTA TIENE MÁS DE 2 ITEMS, QUIERE DECIR QUE LA CURRENTTASK
@@ -725,54 +722,168 @@ class RequestController extends Controller
      */
     public function updateWorkflowInRequests(int $id)
     {
+        /** BUSCAR EL WORKFLOW MODIFICADO */
         $workflow = DB::table('workflows')->find($id);
 
         if ($workflow) {
+            /** CASTEAR TAREAS Y DIAGRAMA */
             $workflow->tasks = json_decode($workflow->tasks);
             $workflow->diagram = json_decode($workflow->diagram);
 
-            $requests = DB::table('requests')->select('id', 'workflow')
+            /** OBTENER LAS SOLICITUDES QUE TENGAN EL WORKFLOW MODIFICADO Y SU WORKFLOW ESTE EN EJECUCIÓN */
+            $requests = DB::table('requests')->select('id', 'workflow', 'currentTask')
                 ->where('id_workflow', $id)
                 ->whereJsonContains('workflow->status', 'Executed')
                 ->get()->toArray();
 
             if ($requests) {
-                $requests[0]->workflow = json_decode($requests[0]->workflow);
+                $flag = true;
+                $totalTasks = array();
+                foreach ($requests as &$request) {
+                    /** OBTENER LA PRIMERA SOLICITUD, TODAS LAS SOLICITUDES DEBERÁN TENER EL MISMO NÚMERO DE .... ? */
+                    //CUIDADO, SI LA SOLICITUD AVANZA, REALMENTE NO SERÁ IGUAL A TODAS
+                    $request->workflow = json_decode($request->workflow);
+                    $request->currentTask = json_decode($request->currentTask);
 
-                $tasksRequests = $requests[0]->workflow->tasks;
-                $tasksWorkflow = $workflow->tasks;
+                    /** OBTENER LAS SECUENCIAS DE LA SOLICITUD */
+                    $sequencesRequests = array_map(function ($task) {
+                        return $task->sequence;
+                    }, $request->workflow->tasks);
 
-                return array_udiff($tasksRequests, $tasksWorkflow, function ($taskRequest, $taskWorkflow) {
-                    if ($taskRequest->id === $taskWorkflow->id && $taskRequest->sequence === $taskWorkflow->sequence) {
-                        return 0;
+                    /** OBTENER LAS SECUENCIAS DEL WORKFLOW MODIFICADO */
+                    $sequencesWorkflow = array_map(function ($task) {
+                        return $task->sequence;
+                    }, $workflow->tasks);
+
+                    /** ¿HAY MAS TAREAS EN LA SOLICITUD O EN EL WORKFLOW?
+                    AL REALIZAR LA COMPARACIÓN, ES NECESARIO COMPARAR EL ARREGLO QUE TENGA MÁS SECUENCIAS */
+                    if (count($sequencesRequests) > count($sequencesWorkflow)) {
+                        /** OBTENER LAS DIFERENCIAS ENTRE LAS SECUENCIAS */
+                        $differences = array_values(array_diff($sequencesRequests, $sequencesWorkflow));
                     } else {
-                        return -1;
+                        /** OBTENER LAS DIFERENCIAS ENTRE LAS SECUENCIAS */
+                        $differences = array_values(array_diff($sequencesWorkflow, $sequencesRequests));
                     }
-                });
 
+                    /** UNA SOLICITUD TIENE UNA CURRENT TASK, SI LAS DIFERENCIAS ESTÁN DESPUÉS DE DICHA SECUENCIA
+                     * SE REGRESARA EL TOTAL DE SECUENCIAS QUE PODRÁN SE MODIFICADAS */
+
+                    /** ARREGLO QUE ALMACENA LAS SEQUENCIAS QUE PODRÁN SER MODIFICADAS */
+                    $canUpdated = array();
+
+                    /** RECORRER LAS SECUENCIAS DE DIFERENCIA Y VERIFICAR SI MODIFICACIÓN ES POSIBLE */
+                    foreach ($differences as &$difference) {
+                        /** SI LA DIFERENCIA ES MAYOR A LA ACTUAL SECUENCIA, ENTONCES NO HAY NINGÚN TIPO DE PROBLEMA */
+                        if ($difference > $request->currentTask->sequence) {
+                            $key = array_search($difference, array_column($request->workflow->tasks, 'changeSequence'));
+                            if ($key) {
+                                $conditionalTask = $request->workflow->tasks[$key]->sequence;
+
+                                $keyWorkflow = array_search($conditionalTask, array_column($workflow->tasks, 'sequence'));
+                                $canUpdated[] = $workflow->tasks[$keyWorkflow]->sequence;
+                            }
+                            $canUpdated[] = $difference;
+
+                        /** SI LA DIFERENCIA ES IGUAL A LA ACTUAL SECUENCIA, ENTONCES SE VERIFICA SI SU SIGUIENTE SEQUENCIA NO CORRESPONDE A
+                         *  UNA TAREA CONDICIONAL, SI ES ASI, TAMBÍEN ES NECESARIO PORQUE PUEDE CAMBIAR SU CHANGESEQUENCE Y NO HABRÁ COINCIDENCIA
+                         *  DE SECUENCIAS */
+                        } else if ($difference === $request->currentTask->sequence) {
+                            /** BUSCAR LA SIGUENTE SECUENCIA DE LA CURRENTTASK */
+                            $key = array_search($request->currentTask->nextSequence, array_column($request->workflow->tasks, 'sequence'));
+                            $nextTask = $request->workflow->tasks[$key];
+                            /** ¿ES CONDICIONAL? TAMBIÉN SE MODIFICARÁ */
+                            if ($nextTask->isConditional){
+                                $canUpdated[] = $nextTask->sequence;
+                            }
+                        }
+                    }
 
-                /*array_map(function ($request) use ($workflow) {
-                    $request->workflow = json_decode($request->workflow);
+                    /** ¿HAY TAREAS QUE PODRÁN SER MODIFICADAS? */
+                    if ($canUpdated) {
+                        /** ¿CUÁL ES LA PRIMERA SECUENCIA?
+                         SI LAS SECUENCIAS SON: 3, 5, 8, 9, BASTA CON EMPEZAR DESDE LA 3 */
+                        $firstSequence = reset($canUpdated);
+
+                        /** ARREGLO QUE ALMACENA LAS TAREAS A MODIFICAR */
+                        $taskToModify = array();
+
+                        /** A PARTIR DEL WORKFLOW MODIFICADO, SE BUSCARÁN LOS NUEVOS CAMBIOS */
+                        foreach ($workflow->tasks as &$task) {
+                            /** ¿LA TAREA (SECUENCIA) ES MAYOR O IGUAL A LA PRIMERA SEQUENCIA QUE SE PUEDE MODIFICAR?
+                             *  Ó
+                             *  ¿LA SIGUIENTE TAREA (SECUENCIA) ES MAYOR A LA PRIMERA SEQUENCIA QUE SE PUEDE MODIFICAR? */
+                            if ($task->sequence >= $firstSequence || $task->nextSequence > $firstSequence) {
+                                /** ¿LA SECUENCIA ES IGUAL LA SECUENCIA DE LA CURRENT TASK? */
+                                if ($task->sequence === $request->currentTask->sequence) {
+                                    /** SI ES ASÍ, DE IGUAL FORMA ES NECESARIO MODIFICARLA PORQUE PUEDE CAMBIAR SU NEXT/CHANGE SEQUENCE
+                                        SIN EMBARGO, SU WORKFLOW DEBERÁ QUEDARSE IGUAL */
+                                    if ($request->currentTask->workflow) {
+                                        $task->workflow = $request->currentTask->workflow;
+                                        $task->id_workflow = $request->currentTask->id_workflow;
+                                    }
+                                    /** EL STATUS Y DISPONIBILIDAD TAMBIÉN SE QUEDAN IGUAL */
+                                    $task->status = $request->currentTask->status;
+                                    $task->isAvailable = $request->currentTask->isAvailable;
+
+                                    /** SE ACTUALIZA LA CURRENT TASK DE LA SOLICITUD */
+                                    $request->currentTask = $task;
+
+                                    /** SE ACTUALIZA EL WORKFLOW DE LA SOLCITUD */
+                                    $key = array_search($request->currentTask->sequence, array_column($request->workflow->tasks, 'sequence'));
+                                    $request->workflow->tasks[$key] = $request->currentTask;
+                                }
+                                $taskToModify[] = $task;
+                            }
+                        }
+                        $firstTaskModify = reset($taskToModify);
+
+                        /*$sequencesWorkflow = array_map(function ($task) {
+                            return $task->sequence;
+                        }, $workflow->tasks);*/
+
+                        foreach ($request->workflow->tasks as $key => $task) {
+                            if ($task->sequence >= $firstTaskModify->sequence) {
+                                /*if (!in_array($task->sequence, $sequencesWorkflow)) {
+                                    unset($request->workflow->tasks[$key]);
+                                }*/
+                                unset($request->workflow->tasks[$key]);
+                            }
+                        }
 
-                    $response = $this->assignWorkflowToRequest($request->workflow, $workflow);
+                        $request->workflow->tasks = array_merge($request->workflow->tasks, $taskToModify);
 
-                    if ($response) {
+                        $response = DB::table('requests')->where('id', $request->id)->update([
+                            'workflow' => json_encode($request->workflow),
+                            'currentTask' => json_encode($request->currentTask),
+                            'updated_at' => Carbon::now()->timezone('America/Mexico_City')->toDateTimeString()
+                        ]);
 
+                        if (!$response) {
+                            $flag = false;
+                        }
                     }
+                }
 
-                    return $request;
-                }, $requests);*/
-
-
+                if ($flag) {
+                    return $this->makeResponse(
+                        false,
+                        "El workflow ha sido modificado con éxito.",
+                        200
+                    );
+                } else {
+                    return $this->makeResponse(
+                        true,
+                        "Hubo un error al modificar el workflow de las solicitudes.",
+                        401
+                    );
+                }
             } else {
                 return $this->makeResponse(
                     false,
-                    "El workflow fue modificado con éxito.",
+                    "El workflow ha sido modificado con éxito.",
                     200
                 );
             }
-
-            return $requests;
         } else {
             return $this->makeResponse(
                 true,
@@ -796,8 +907,6 @@ class RequestController extends Controller
         /** SERÁ TRUE CUANDO EXISTA UNA ACTUALIZACIÓN EN UNA TAREA */
         $flag = false;
 
-
-
         $workflow->tasks = array_map(function ($task) use ($workflowChange, &$flag) {
             /** SOLO SI TIENE WORKFLOW SE HARÁ LA VERIFICACIÓN */
             if ($task->workflow) {
@@ -821,9 +930,6 @@ class RequestController extends Controller
             return $task;
         }, $workflow->tasks);
 
-
-
-
         /** SI ES TRUE SE ENVIA EL WORKFLOW CON SUS TAREAS MODIFICADAS Y EN CASO CONTRARIO SE RETORNA UN FALSE */
         return $flag ? $workflow : $flag;
     }
@@ -1012,69 +1118,10 @@ class RequestController extends Controller
 
         /** CANCELAR EL WORKFLOW */
         $workflow->status = 'Canceled';
-        $workflow->isCompleted = false;
 
         return $workflow;
     }
 
-    /**
-     * Cancelar un Workflow
-     *
-     * @param $request
-     * @param $nextTask
-     * @return mixed
-     */
-    private function cancelWorkflowInTask2s($request, $nextTask) {
-        $flag = false;
-
-        if ($request->workflow->isStopped) {
-            $item = array_pop($request->workflowList);
-
-            if ($item->currentTask->workflow) {
-                $item->currentTask->workflow = $this->cancelWorkflow($item->currentTask->workflow);
-            }
-
-            $key = array_search($item->currentTask->sequence, array_column($item->workflow->tasks, 'sequence'));
-            $item->workflow->tasks[$key] = $item->currentTask;
-
-            /** VERIFICAR SI NO ES LA ÚLTIMA TAREA (FINALIZAR WORKFLOW) */
-            $lastTask = end($item->workflow->tasks);
-
-            if ($lastTask->id === $nextTask->id) {
-                /** SI LO ES, SE COMPLETA LA TAREA Y SE VALIDA PARA DESPUÉS ASIGNARSE */
-                $nextTask->status = 'Completed';
-                $nextTask->isValidated = true;
-            } else {
-                $item->currentTask = $nextTask;
-                $item->workflowList[] = $item;
-            }
-        } else {
-            if ($request->currentTask->workflow) {
-                $request->currentTask->workflow = $this->cancelWorkflow($request->currentTask->workflow);
-            }
-
-            $key = array_search($request->currentTask->sequence, array_column($request->workflow->tasks, 'sequence'));
-            $request->workflow->tasks[$key] = $request->currentTask;
-
-            $request->currentTask = $nextTask;
-        }
-
-        $response = DB::table('requests')->where('id', $request->id)->update([
-            'workflowList' => json_encode($request->workflowList),
-            'workflow' => json_encode($request->workflow),
-            'currentTask' => json_encode($request->currentTask),
-            'updated_at' => Carbon::now()->timezone('America/Mexico_City')->toDateTimeString()
-        ]);
-
-        return $request;
-
-        if ($response) {
-            return $this->executeRequest($request->id);
-        } else {
-            return false;
-        }
-    }
-
     /**
      * Cancelar un Workflow
      *

+ 10 - 34
app/Http/Controllers/TaskController.php

@@ -29,22 +29,11 @@ class TaskController extends Controller
             }
             $task->employeesNotify = json_decode($task->employeesNotify);
             $task->employeesValidate = json_decode($task->employeesValidate);
-            $task->validationRules = json_decode($task->validationRules);
 
             return $task;
         }, $tasks);
     }
 
-    /**
-     * Show the form for creating a new resource.
-     *
-     * @return Response
-     */
-    public function create()
-    {
-        //
-    }
-
     /**
      * Store a newly created resource in storage.
      *
@@ -59,13 +48,12 @@ class TaskController extends Controller
             'sequence' => 'sometimes|integer|nullable',
             'employeesNotify' => 'required|array',
             'employeesValidate' => 'array',
-            'validationRules' => 'array',
             'isAvailable' => 'required|boolean',
             'isValidated' => 'required|boolean',
-            'notification' => 'required|boolean',
+            'isNotified' => 'required|boolean',
             'isConditional' => 'required|boolean',
             'id_workflow' => 'sometimes|required|integer|nullable|exists:workflows,id',
-            'id_module' => 'sometimes|required|integer|nullable|exists:modules,id',
+            'id_module' => 'sometimes|required|string|max:50|nullable|exists:modules,id',
         ]);
 
         if ($validator->fails()) {
@@ -81,7 +69,9 @@ class TaskController extends Controller
 
         if ($request->has('id_workflow')) {
             $workflow = DB::table('workflows')->find($request->id_workflow);
+            $workflow->diagram = json_decode($workflow->diagram);
             $workflow->tasks = json_decode($workflow->tasks);
+            $workflow->fields = json_decode($workflow->fields);
         }
 
         $task = [
@@ -90,10 +80,9 @@ class TaskController extends Controller
             'workflow' =>  json_encode($workflow),
             'employeesNotify' => json_encode($request->employeesNotify ),
             'employeesValidate' => json_encode($request->employeesValidate ),
-            'validationRules' => json_encode($request->validationRules),
             'isAvailable' => $request->isAvailable,
             'isValidated' => $request->isValidated,
-            'notification' => $request->notification,
+            'isNotified' => $request->isNotified,
             'isConditional' => $request->isConditional,
             'id_workflow' => $request->has('id_workflow') ? $request->id_workflow : null,
             'id_module' => $request->has('id_module') ? $request->id_module : null,
@@ -122,7 +111,6 @@ class TaskController extends Controller
             }
             $task->employeesNotify = json_decode($task->employeesNotify);
             $task->employeesValidate = json_decode($task->employeesValidate);
-            $task->validationRules = json_decode($task->validationRules);
 
             return $task;
         } else {
@@ -130,17 +118,6 @@ class TaskController extends Controller
         }
     }
 
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param  int  $id
-     * @return Response
-     */
-    public function edit($id)
-    {
-        //
-    }
-
     /**
      * Update the specified resource in storage.
      *
@@ -156,13 +133,12 @@ class TaskController extends Controller
             'sequence' => 'sometimes|integer|nullable',
             'employeesNotify' => 'required|array',
             'employeesValidate' => 'array',
-            'validationRules' => 'array',
             'isAvailable' => 'required|boolean',
             'isValidated' => 'required|boolean',
-            'notification' => 'required|boolean',
+            'isNotified' => 'required|boolean',
             'isConditional' => 'required|boolean',
             'id_workflow' => 'sometimes|required|integer|nullable|exists:workflows,id',
-            'id_module' => 'sometimes|required|integer|nullable|exists:modules,id',
+            'id_module' => 'sometimes|required|string|max:50|nullable|exists:modules,id',
         ]);
 
         if ($validator->fails()) {
@@ -178,8 +154,9 @@ class TaskController extends Controller
 
         if ($request->has('id_workflow')) {
             $workflow = DB::table('workflows')->find($request->id_workflow);
-            $workflow->tasks = json_decode($workflow->tasks);
             $workflow->diagram = json_decode($workflow->diagram);
+            $workflow->tasks = json_decode($workflow->tasks);
+            $workflow->fields = json_decode($workflow->fields);
         }
 
         $task = [
@@ -188,10 +165,9 @@ class TaskController extends Controller
             'workflow' =>  json_encode($workflow),
             'employeesNotify' => json_encode($request->employeesNotify),
             'employeesValidate' => json_encode($request->employeesValidate),
-            'validationRules' => json_encode($request->validationRules),
             'isAvailable' => $request->isAvailable,
             'isValidated' => $request->isValidated,
-            'notification' => $request->notification,
+            'isNotified' => $request->isNotified,
             'isConditional' => $request->isConditional,
             'id_workflow' => $request->has('id_workflow') ? $request->id_workflow : null,
             'id_module' => $request->has('id_module') ? $request->id_module : null,

+ 62 - 50
app/Http/Controllers/WorkflowController.php

@@ -2,8 +2,10 @@
 
 namespace App\Http\Controllers;
 
+use Illuminate\Http\RedirectResponse;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
+use Illuminate\Routing\ResponseFactory;
 use Illuminate\Support\Carbon;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Validator;
@@ -23,6 +25,7 @@ class WorkflowController extends Controller
         return array_map(function ($workflow) {
             $workflow->diagram = json_decode($workflow->diagram);
             $workflow->tasks = json_decode($workflow->tasks);
+            $workflow->fields = json_decode($workflow->fields);
 
             return $workflow;
         }, $workflows->all() );
@@ -46,18 +49,18 @@ class WorkflowController extends Controller
             'tasks.*.sequence' => 'required|integer',
             'tasks.*.workflow' => 'array|nullable',
             'tasks.*.employeesNotify' => 'required|array',
-            'tasks.*.employeesNotify.*.id' => 'required|integer|exists:users,id',
+            'tasks.*.employeesNotify.*.id' => 'required|string|max:50|exists:users,id',
             'tasks.*.employeesValidate' => 'array',
-            'tasks.*.employeesValidate.*.id' => 'required|integer|exists:users,id',
-            'tasks.*.validationRules' => 'array',
+            'tasks.*.employeesValidate.*.id' => 'required|string|max:50|exists:users,id',
             'tasks.*.status' => ['required', Rule::in(['Pending', 'Executed', 'Completed'])],
             'tasks.*.isValidated' => 'required|boolean',
-            'tasks.*.notification' => 'required|boolean',
+            'tasks.*.isNotified' => 'required|boolean',
             'tasks.*.isConditional' => 'required|boolean',
             'tasks.*.id_workflow' => 'sometimes|integer|nullable|exists:workflows,id',
-            'tasks.*.id_module' => 'sometimes|integer|nullable|exists:modules,id',
+            'tasks.*.id_module' => 'sometimes|string|max:50|nullable|exists:modules,id',
+            'fields' => 'array',
             'isAutomatic' => 'required|boolean',
-            'id_module' => 'required|integer|exists:modules,id'
+            'id_module' => 'required|string|max:50|exists:modules,id'
         ]);
 
         if ($validator->fails()) {
@@ -74,8 +77,9 @@ class WorkflowController extends Controller
             'description' => $request->description,
             'version' => 'v1',
             'diagram' => json_encode($request->diagram),
-            'tasks' => json_encode($request->tasks),
-            'isCompleted' => false,
+            'tasks' => $request->has('fields') ? json_encode([]) : json_encode($request->tasks),
+            'fields' => $request->has('fields') ? json_encode($request->fields) : json_encode([]),
+            'isForm' => $request->has('fields'),
             'isAutomatic' => $request->isAutomatic,
             'isAvailable' => true,
             'isStopped' => false,
@@ -102,6 +106,7 @@ class WorkflowController extends Controller
         if ($workflow) {
             $workflow->diagram = json_decode($workflow->diagram);
             $workflow->tasks = json_decode($workflow->tasks);
+            $workflow->fields = json_decode($workflow->fields);
 
             return $workflow;
         } else {
@@ -114,7 +119,7 @@ class WorkflowController extends Controller
      *
      * @param  \Illuminate\Http\Request  $request
      * @param int $id
-     * @return \Illuminate\Http\Response
+     * @return ResponseFactory|RedirectResponse|Response
      */
     public function update(Request $request, int $id)
     {
@@ -128,22 +133,20 @@ class WorkflowController extends Controller
             'tasks.*.sequence' => 'required|integer',
             'tasks.*.workflow' => 'array|nullable',
             'tasks.*.employeesNotify' => 'required|array',
-            'tasks.*.employeesNotify.*.id' => 'required|integer|exists:users,id',
+            'tasks.*.employeesNotify.*.id' => 'required|string|max:50|exists:users,id',
             'tasks.*.employeesValidate' => 'array',
-            'tasks.*.employeesValidate.*.id' => 'required|integer|exists:users,id',
-            'tasks.*.validationRules' => 'array',
+            'tasks.*.employeesValidate.*.id' => 'required|string|max:50|exists:users,id',
             'tasks.*.status' => ['required', Rule::in(['Pending', 'Executed', 'Completed'])],
             'tasks.*.isAvailable' => 'required|boolean',
             'tasks.*.isValidated' => 'required|boolean',
-            'tasks.*.notification' => 'required|boolean',
+            'tasks.*.isNotified' => 'required|boolean',
             'tasks.*.isConditional' => 'required|boolean',
             'tasks.*.id_workflow' => 'sometimes|integer|nullable|exists:workflows,id',
-            'tasks.*.id_module' => 'sometimes|integer|nullable|exists:modules,id',
-            'isCompleted' => 'required|boolean',
+            'tasks.*.id_module' => 'sometimes|string|max:50|nullable|exists:modules,id',
             'isAutomatic' => 'required|boolean',
             'isAvailable' => 'required|boolean',
             'isStopped' => 'required|boolean',
-            'id_module' => 'required|integer|exists:modules,id'
+            'id_module' => 'required|string|max:50|exists:modules,id'
         ]);
 
         if ($validator->fails()) {
@@ -168,7 +171,6 @@ class WorkflowController extends Controller
             $currentWorkflow->version = $version;
             $currentWorkflow->diagram = $request->diagram;
             $currentWorkflow->tasks = $request->tasks;
-            $currentWorkflow->isCompleted = $request->isCompleted;
             $currentWorkflow->isAutomatic = $request->isAutomatic;
             $currentWorkflow->isAvailable = $request->isAvailable;
             $currentWorkflow->isStopped = $request->isStopped;
@@ -188,8 +190,12 @@ class WorkflowController extends Controller
             if ($response && $responseModule){
                 /** ES NECESARIO ACTUALIZAR LOS WORKFLOWS EN LAS TAREAS */
                 $response = $this->updateWorkflowInTasks($id);
-
-                return $this->validData($response);
+                //FALTA enviar la respuesta, si esto fallo tal vez no sea necesario modificar la solicitud, PENDIENTE
+                if ($response) {
+                    return redirect()->route('updateWorkflowInRequests', ['id' => $id]);
+                } else {
+                    return $this->validData(false);
+                }
             } else {
                 return $this->validData(false);
             }
@@ -437,21 +443,23 @@ class WorkflowController extends Controller
             foreach ($workflows as &$workflow) {
                 $workflow->tasks = json_decode($workflow->tasks);
 
-                /** VERIFICAR LAS TAREAS DE CADA WORKFLOW Y VERIFICAR SI HAY MÁS WORKFLOWS DENTRO */
-                $response = $this->assignWorkflowToTask($workflow, $id, $workflowChange);
+                if ($workflow->tasks) {
+                    /** VERIFICAR LAS TAREAS DE CADA WORKFLOW Y VERIFICAR SI HAY MÁS WORKFLOWS DENTRO */
+                    $response = $this->assignWorkflowToTask($workflow, $id, $workflowChange);
 
-                /** SI EL MÉTODO REGRESA UN WORKFLOW, SE ASIGNA Y POSTERIORMENTE SE ACTUALIZA */
-                if ($response) {
-                    $workflow = $response;
+                    /** SI EL MÉTODO REGRESA UN WORKFLOW, SE ASIGNA Y POSTERIORMENTE SE ACTUALIZA */
+                    if ($response) {
+                        $workflow = $response;
 
-                    $updatedResponse = DB::table('workflows')->where('id', $workflow->id)->update([
-                        'tasks' => $workflow->tasks,
-                        'updated_at' => Carbon::now()->timezone('America/Mexico_City')->toDateTimeString()
-                    ]);
+                        $updatedResponse = DB::table('workflows')->where('id', $workflow->id)->update([
+                            'tasks' => $workflow->tasks,
+                            'updated_at' => Carbon::now()->timezone('America/Mexico_City')->toDateTimeString()
+                        ]);
 
-                    /** SI LA ACTUALIZACIÓN FALLA, SE RETORNARÁ ERROR GENERAL */
-                    if (!$updatedResponse)  {
-                        $responseWorkflow = false;
+                        /** SI LA ACTUALIZACIÓN FALLA, SE RETORNARÁ ERROR GENERAL */
+                        if (!$updatedResponse)  {
+                            $responseWorkflow = false;
+                        }
                     }
                 }
             }
@@ -476,28 +484,32 @@ class WorkflowController extends Controller
         /** SERÁ TRUE CUANDO EXISTA UNA ACTUALIZACIÓN EN UNA TAREA */
         $flag = false;
 
-        $workflow->tasks = array_map(function ($task) use ($id, $workflowChange, &$flag) {
-            /** SOLO SI LA TAREA TIENE WORKFLOW SE HARÁ LA VERIFICACIÓN */
-            if ($task->workflow) {
-                /** PUEDE SER QUE ALGUNA TAREA DEL WORKFLOW COINCIDA CON EL WORKFLOW MODIFICADO. SIN EMBARGO,
-                 * SI NO COINCIDE ES NECESARIO VERIFICAR QUE EL WORKFLOW NO CONTENGA UNA TAREA CON ESE WORKFLOW */
-                if ($task->id_workflow === $id){
-                    $task->workflow = $workflowChange;
-                    $flag = true;
-                } else {
-                    /** AL INSPECCIONAR EL WORKFLOW DE LA TAREA,
-                     * SE REUTILIZA EL MÉTODO QUE INSPECCIONA LAS TAREAS DE UN WORKFLOW */
-                    $response = $this->assignWorkflowToTask($task->workflow, $id, $workflowChange);
-
-                    /** SI SE OBTIENE UN WORKFLOW, SE ASIGNA A LA TAREA */
-                    if ($response){
-                        $task->workflow = $response;
+        try {
+            $workflow->tasks = array_map(function ($task) use ($id, $workflowChange, &$flag) {
+                /** SOLO SI LA TAREA TIENE WORKFLOW SE HARÁ LA VERIFICACIÓN */
+                if ($task->workflow) {
+                    /** PUEDE SER QUE ALGUNA TAREA DEL WORKFLOW COINCIDA CON EL WORKFLOW MODIFICADO. SIN EMBARGO,
+                     * SI NO COINCIDE ES NECESARIO VERIFICAR QUE EL WORKFLOW NO CONTENGA UNA TAREA CON ESE WORKFLOW */
+                    if ($task->id_workflow === $id){
+                        $task->workflow = $workflowChange;
                         $flag = true;
+                    } else {
+                        /** AL INSPECCIONAR EL WORKFLOW DE LA TAREA,
+                         * SE REUTILIZA EL MÉTODO QUE INSPECCIONA LAS TAREAS DE UN WORKFLOW */
+                        $response = $this->assignWorkflowToTask($task->workflow, $id, $workflowChange);
+
+                        /** SI SE OBTIENE UN WORKFLOW, SE ASIGNA A LA TAREA */
+                        if ($response){
+                            $task->workflow = $response;
+                            $flag = true;
+                        }
                     }
                 }
-            }
-            return $task;
-        }, $workflow->tasks);
+                return $task;
+            }, $workflow->tasks);
+        }catch (\Exception $e) {
+            /** SAVE LOGS */
+        }
 
         /** SI ES TRUE SE ENVIA EL WORKFLOW CON SUS TAREAS MODIFICADAS Y EN CASO CONTRARIO SE RETORNA UN FALSE */
         return $flag ? $workflow : $flag;

+ 2 - 1
database/migrations/2014_10_12_000000_create_users_table.php

@@ -14,7 +14,8 @@ class CreateUsersTable extends Migration
     public function up()
     {
         Schema::create('users', function (Blueprint $table) {
-            $table->id();
+            //$table->id();
+            $table->string('id', 50)->primary();
             $table->string('name');
             $table->string('email')->unique();
             $table->timestamp('email_verified_at')->nullable();

+ 2 - 1
database/migrations/2022_03_02_154508_create_modules_table.php

@@ -14,7 +14,8 @@ class CreateModulesTable extends Migration
     public function up()
     {
         Schema::create('modules', function (Blueprint $table) {
-            $table->id();
+            //$table->id();
+            $table->string('id', 50)->primary();
             $table->string('name');
             $table->string('description');
             $table->json('defaultWorkflow')->nullable();

+ 6 - 2
database/migrations/2022_03_02_164959_create_workflows_table.php

@@ -20,12 +20,16 @@ class CreateWorkflowsTable extends Migration
             $table->string('version');
             $table->json('diagram');
             $table->json('tasks');
+            $table->json('fields');
             $table->enum('status', ['Pending', 'Executed', 'Canceled', 'Completed'])->default('Pending');
-            $table->boolean('isCompleted');
+            $table->boolean('isForm');
+            //$table->boolean('isCompleted');
             $table->boolean('isAutomatic');
             $table->boolean('isAvailable');
             $table->boolean('isStopped');
-            $table->foreignId('id_module')->constrained('modules')->onUpdate('cascade');
+            //$table->foreignId('id_module')->constrained('modules')->onUpdate('cascade');
+            $table->string('id_module', 50);
+            $table->foreign('id_module')->references('id')->on('modules')->onUpdate('cascade');
             $table->timestamps();
         });
     }

+ 5 - 3
database/migrations/2022_03_02_165013_create_tasks_table.php

@@ -23,14 +23,16 @@ class CreateTasksTable extends Migration
             $table->json('workflow')->nullable();
             $table->json('employeesNotify');
             $table->json('employeesValidate');
-            $table->json('validationRules')->nullable();
             $table->enum('status', ['Pending', 'Executed', 'Canceled', 'Completed'])->default('Pending');
             $table->boolean('isAvailable');
             $table->boolean('isValidated');
-            $table->boolean('notification');
             $table->boolean('isConditional');
+            //$table->boolean('notification');
+            $table->boolean('isNotified');
             $table->foreignId('id_workflow')->nullable()->constrained('workflows')->onUpdate('cascade');
-            $table->foreignId('id_module')->nullable()->constrained('modules')->onUpdate('cascade');
+            //$table->foreignId('id_module')->nullable()->constrained('modules')->onUpdate('cascade');
+            $table->string('id_module', 50)->nullable();
+            $table->foreign('id_module')->references('id')->on('modules')->onUpdate('cascade');
             $table->timestamps();
         });
     }

+ 9 - 4
database/migrations/2022_03_10_153410_create_requests_table.php

@@ -19,12 +19,17 @@ class CreateRequestsTable extends Migration
             $table->json('workflow');
             $table->json('workflowList')->nullable();
             $table->json('currentTask');
-            $table->boolean('isActiveWorkflow');
-            $table->boolean('isCompleted');
+            $table->enum('status', ['Executed', 'Canceled', 'Completed'])->default('Executed');
+            //$table->boolean('isActiveWorkflow');
+            //$table->boolean('isCompleted');
             $table->boolean('isValidated');
-            $table->foreignId('id_module')->constrained('modules')->onUpdate('cascade');
+            //$table->foreignId('id_module')->constrained('modules')->onUpdate('cascade');
+            $table->string('id_module', 50);
+            $table->foreign('id_module')->references('id')->on('modules')->onUpdate('cascade');
             $table->foreignId('id_workflow')->constrained('workflows')->onUpdate('cascade');
-            $table->foreignId('id_user')->constrained('users')->onUpdate('cascade');
+            //$table->foreignId('id_user')->constrained('users')->onUpdate('cascade');
+            $table->string('id_user', 50);
+            $table->foreign('id_user')->references('id')->on('users')->onUpdate('cascade');
             $table->timestamps();
         });
     }

+ 3 - 1
database/migrations/2022_03_11_165205_create_notification_histories_table.php

@@ -18,7 +18,9 @@ class CreateNotificationHistoriesTable extends Migration
             $table->json('content');
             $table->json('employees');
             $table->foreignId('id_request')->constrained('requests');
-            $table->foreignId('id_user')->constrained('users');
+            //->foreignId('id_user')->constrained('users');
+            $table->string('id_user', 50);
+            $table->foreign('id_user')->references('id')->on('users')->onUpdate('cascade');
             $table->timestamps();
         });
     }

+ 1 - 1
routes/api.php

@@ -38,7 +38,7 @@ Route::get('/workflowsHistory/{workflow}/versions/{v1}/{v2}', [WorkflowHistoryCo
 
 Route::resource('requests', RequestController::class);
 Route::get('/requests/user/{id}', [RequestController::class, 'showByUserId']);
-Route::get('/requests/update/workflow/{id}', [RequestController::class, 'updateWorkflowInRequests'])->name('updateWorkflowInRequests');
+Route::match(['get', 'put'],'/requests/update/workflow/{id}', [RequestController::class, 'updateWorkflowInRequests'])->name('updateWorkflowInRequests');
 Route::match(['get', 'put'], '/requests/execute/{id}', [RequestController::class, 'executeRequest'])->name('executeRequest');
 
 Route::resource('requests_workflow', RequestWorkflowController::class);