[add] Listing of employee types

This commit is contained in:
Jose Pabl Domingo Aramburo Sanchez 2018-08-05 22:31:40 -06:00
parent 6b289695c7
commit 692f52b533
4 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace App\Application;
class EmployeeApplication{
private $pdo;
private $cryptographyService;
private $asserts;
function __construct($mysql, $cryptographyService, $asserts){
$this->cryptographyService = $cryptographyService;
$this->pdo = $mysql;
$this->asserts = $asserts;
$this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
}
function listEmployeeTypes(){
$stmt = $this->pdo->prepare("SELECT id, name FROM employeeType WHERE status = 'ACTIVE'");
$stmt->execute();
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
}
$stmt = null;
return $results;
}
}
?>

View File

@ -62,3 +62,9 @@ $container['sessionApplication'] = function ($c) {
$sessionApplication = new App\Application\SessionApplication($c['mysql'], $c['cryptographyService'], $c['asserts']);
return $sessionApplication;
};
// The employee application
$container['employeeApplication'] = function ($c) {
$employeeApplication = new App\Application\EmployeeApplication($c['mysql'], $c['cryptographyService'], $c['asserts']);
return $employeeApplication;
};

View File

@ -34,3 +34,9 @@ $app->post('/api/session/logout', function (Request $request, Response $response
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->sessionApplication->destroySession()));
});
$app->get('/api/employee/types', function (Request $request, Response $response, array $args) {
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->listEmployeeTypes()));
});

View File

@ -45,3 +45,18 @@ CREATE TABLE IF NOT EXISTS `users` (
INSERT INTO users (idPerson, name, password)
VALUES (1, 'sloth', '$2y$12$51mfESaLEGXDT4u9Bd9kiOHEpaJ1Bx4SEcVwsU5K6jVPMNkrnpJAa');
DROP TABLE IF EXISTS employeeType;
CREATE TABLE IF NOT EXISTS `employeeType` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL comment 'Type or rol that the employee can be',
`status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified',
PRIMARY KEY (`id`),
UNIQUE (`name`)
);
INSERT INTO employeeType (name) VALUES ('Chofer'),
('Cargador'),
('Auxiliar');