From 2d3f52372c264c4a66033c7118e6b410e000d7e8 Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 01:35:52 -0600 Subject: [PATCH 1/5] [add} Employee id by code --- .../src/application/EmployeeApplication.php | 24 +++++++++++++++++++ api-payroll/src/routes.php | 8 +++++++ 2 files changed, 32 insertions(+) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index de8652b..4368015 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -150,5 +150,29 @@ class EmployeeApplication{ return $response; } + + /** + * @param $code + * @return mixed + */ + function getIdEmployeeTypeByCode($code){ + $stmt = $this->pdo->prepare("SELECT COALESCE((SELECT + et.id + FROM + employees e + INNER JOIN + employeeType et ON et.id = e.idEmployeeType + WHERE + e.code = :code), 0) AS id"); + + $stmt->execute(array(':code' => $code)); + $results = $stmt->fetchAll(); + if(!$results){ + exit($this->databaseSelectQueryErrorMessage); + } + $stmt = null; + + return $results[0]['id']; + } } ?> \ No newline at end of file diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index 97df0fe..6d91c0d 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -48,3 +48,11 @@ $app->post('/api/employee', function ($request, $response) { ->withHeader('Content-Type', 'application/json') ->write(json_encode($this->employeeApplication->saveNewEmployee($requestData))); }); + +$app->get('/api/employee/type/{code}', function (Request $request, Response $response, array $args) { + $code = $args['code']; + + return $response->withStatus(200) + ->withHeader('Content-Type', 'application/json') + ->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code))); +}); From 30420975c4c570fe4d2b10153167cf845613e453 Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 01:52:06 -0600 Subject: [PATCH 2/5] [add] Getting employee data --- .../src/application/EmployeeApplication.php | 27 +++++++++++++++++++ api-payroll/src/routes.php | 8 ++++++ 2 files changed, 35 insertions(+) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 4368015..636df92 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -174,5 +174,32 @@ class EmployeeApplication{ return $results[0]['id']; } + + function getEmployeeDataById($idEmployee){ + $stmt = $this->pdo->prepare("SELECT + p.id, + p.firstName, + p.middleName, + IFNULL(p.lastName, '') AS lastName, + p.email, + p.phone, + e.code, + e.contractType + FROM + employees e + INNER JOIN + persons p ON p.id = e.idPerson + WHERE + e.id = :idEmployee"); + + $stmt->execute(array(':idEmployee' => $idEmployee)); + $results = $stmt->fetchAll(); + if(!$results){ + exit($this->databaseSelectQueryErrorMessage); + } + $stmt = null; + + return $results[0]; + } } ?> \ No newline at end of file diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index 6d91c0d..6101d76 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -56,3 +56,11 @@ $app->get('/api/employee/type/{code}', function (Request $request, Response $res ->withHeader('Content-Type', 'application/json') ->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code))); }); + +$app->get('/api/employee/{idEmployee}', function (Request $request, Response $response, array $args) { + $idEmployee = $args['idEmployee']; + + return $response->withStatus(200) + ->withHeader('Content-Type', 'application/json') + ->write(json_encode($this->employeeApplication->getEmployeeDataById($idEmployee))); +}); \ No newline at end of file From 666b17c0dc3a83de3c7f9e0d54663f571bc19b86 Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 02:07:23 -0600 Subject: [PATCH 3/5] [add] Returning employee data by id --- .../src/application/EmployeeApplication.php | 34 ++++++++++++++++++- api-payroll/src/routes.php | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) 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 From f441696b960b7e02d9ff56468923d92ebb7eae06 Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 02:11:24 -0600 Subject: [PATCH 4/5] [mod] Null last names retured as empty in employee data --- api-payroll/src/application/EmployeeApplication.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index e5a3d41..8964b51 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -222,7 +222,11 @@ class EmployeeApplication{ "idPerson" => (int)$employeeData['idPerson'], "firstName" => $this->cryptographyService->decryptString($employeeData['firstName']), "middleName" => $this->cryptographyService->decryptString($employeeData['middleName']), - "lastName" => $this->cryptographyService->decryptString($employeeData['lastName']), + + "lastName" => strlen($employeeData['lastName']) > 0 + ? $this->cryptographyService->decryptString($employeeData['lastName']) + : '', + "email" => $this->cryptographyService->decryptString($employeeData['email']), "phone" => $employeeData['phone'], "code" => $employeeData['code'], From 0deb89ed538531f4bd64461e46b5371c3a45cb4d Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 02:17:13 -0600 Subject: [PATCH 5/5] [mod] Select of employee times made multi line --- api-payroll/src/application/EmployeeApplication.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 8964b51..206e2b3 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -5,6 +5,7 @@ class EmployeeApplication{ private $pdo; private $cryptographyService; private $asserts; + private $settings; function __construct($employeeSettings, $mysql, $cryptographyService, $asserts){ $this->settings = $employeeSettings; @@ -20,7 +21,12 @@ class EmployeeApplication{ * @return array */ function listEmployeeTypes(){ - $stmt = $this->pdo->prepare("SELECT id, name FROM employeeType WHERE status = 'ACTIVE'"); + $stmt = $this->pdo->prepare("SELECT + id, name + FROM + employeeType + WHERE + status = 'ACTIVE'"); $stmt->execute(); $results = $stmt->fetchAll(); @@ -226,7 +232,7 @@ class EmployeeApplication{ "lastName" => strlen($employeeData['lastName']) > 0 ? $this->cryptographyService->decryptString($employeeData['lastName']) : '', - + "email" => $this->cryptographyService->decryptString($employeeData['email']), "phone" => $employeeData['phone'], "code" => $employeeData['code'],