[add] Returning employee data by id

This commit is contained in:
Jose Pabl Domingo Aramburo Sanchez 2018-08-06 02:07:23 -06:00
parent 30420975c4
commit 666b17c0dc
2 changed files with 34 additions and 2 deletions

View File

@ -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;
}
}
?>

View File

@ -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)));
});