[add] Listing of employee types
This commit is contained in:
parent
6b289695c7
commit
692f52b533
31
api-payroll/src/application/EmployeeApplication.php
Normal file
31
api-payroll/src/application/EmployeeApplication.php
Normal 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;
|
||||
}
|
||||
}
|
||||
?>
|
@ -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;
|
||||
};
|
@ -33,4 +33,10 @@ $app->post('/api/session/logout', function (Request $request, Response $response
|
||||
return $response->withStatus(200)
|
||||
->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()));
|
||||
});
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user