diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 636df92..e5a3d41 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -175,9 +175,15 @@ class EmployeeApplication{ return $results[0]['id']; } + /** + * Gets the data associated with the employee + * + * @param $idEmployee + * @return array + */ function getEmployeeDataById($idEmployee){ $stmt = $this->pdo->prepare("SELECT - p.id, + p.id AS idPerson, p.firstName, p.middleName, IFNULL(p.lastName, '') AS lastName, @@ -201,5 +207,31 @@ class EmployeeApplication{ return $results[0]; } + + /** + * Acts as a man in the middle for the getEmployeeDataById method to decrypt the contents + * and make the necesary data manipulations + * + * @param $idEmployee + * @return array + */ + function proxyGetEmployeeDataById($idEmployee){ + $employeeData = $this->getEmployeeDataById($idEmployee); + + $response = array( + "idPerson" => (int)$employeeData['idPerson'], + "firstName" => $this->cryptographyService->decryptString($employeeData['firstName']), + "middleName" => $this->cryptographyService->decryptString($employeeData['middleName']), + "lastName" => $this->cryptographyService->decryptString($employeeData['lastName']), + "email" => $this->cryptographyService->decryptString($employeeData['email']), + "phone" => $employeeData['phone'], + "code" => $employeeData['code'], + "contractType" => $employeeData['contractType'] + + ); + + return $response; + + } } ?> \ No newline at end of file diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index 6101d76..da1eda3 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -62,5 +62,5 @@ $app->get('/api/employee/{idEmployee}', function (Request $request, Response $re return $response->withStatus(200) ->withHeader('Content-Type', 'application/json') - ->write(json_encode($this->employeeApplication->getEmployeeDataById($idEmployee))); + ->write(json_encode($this->employeeApplication->proxyGetEmployeeDataById($idEmployee))); }); \ No newline at end of file