[add] Higher than zero asserting
This commit is contained in:
parent
112f78c1de
commit
1500aef977
@ -58,7 +58,7 @@ class EmployeeApplication{
|
|||||||
function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
||||||
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
|
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
|
||||||
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
|
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
|
||||||
$this->asserts->isNotEmpty($middleName, "The birth date can't be empty.");
|
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
|
||||||
$this->asserts->isNotEmpty($email, "The email can't be empty.");
|
$this->asserts->isNotEmpty($email, "The email can't be empty.");
|
||||||
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||||
|
|
||||||
@ -89,6 +89,10 @@ class EmployeeApplication{
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){
|
function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){
|
||||||
|
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
|
||||||
|
$this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0");
|
||||||
|
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||||
|
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
|
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
|
||||||
VALUES (:idEmployeeType, :idPerson, :code, :contractType)");
|
VALUES (:idEmployeeType, :idPerson, :code, :contractType)");
|
||||||
@ -177,6 +181,8 @@ class EmployeeApplication{
|
|||||||
* @return Integer
|
* @return Integer
|
||||||
*/
|
*/
|
||||||
function getIdPersonByIdEmployee($idEmployee){
|
function getIdPersonByIdEmployee($idEmployee){
|
||||||
|
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
COALESCE((SELECT
|
COALESCE((SELECT
|
||||||
idPerson
|
idPerson
|
||||||
@ -229,6 +235,8 @@ class EmployeeApplication{
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getEmployeeDataById($idEmployee){
|
function getEmployeeDataById($idEmployee){
|
||||||
|
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare("SELECT
|
$stmt = $this->pdo->prepare("SELECT
|
||||||
p.id AS idPerson,
|
p.id AS idPerson,
|
||||||
p.firstName,
|
p.firstName,
|
||||||
@ -263,6 +271,8 @@ class EmployeeApplication{
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function proxyGetEmployeeDataById($idEmployee){
|
function proxyGetEmployeeDataById($idEmployee){
|
||||||
|
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||||
|
|
||||||
$employeeData = $this->getEmployeeDataById($idEmployee);
|
$employeeData = $this->getEmployeeDataById($idEmployee);
|
||||||
|
|
||||||
$response = array(
|
$response = array(
|
||||||
@ -306,6 +316,13 @@ class EmployeeApplication{
|
|||||||
* @param $phone string
|
* @param $phone string
|
||||||
*/
|
*/
|
||||||
function updatePerson($idPerson, $firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
function updatePerson($idPerson, $firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
||||||
|
$this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0");
|
||||||
|
$this->asserts->isNotEmpty($firstName, "The first name can't be empty.");
|
||||||
|
$this->asserts->isNotEmpty($middleName, "The middle name can't be empty.");
|
||||||
|
$this->asserts->isNotEmpty($birthDate, "The birth date can't be empty.");
|
||||||
|
$this->asserts->isNotEmpty($email, "The email can't be empty.");
|
||||||
|
$this->asserts->isNotEmpty($phone, "The phone number can't be empty.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("UPDATE persons
|
$stmt = $this->pdo->prepare("UPDATE persons
|
||||||
SET
|
SET
|
||||||
@ -335,6 +352,11 @@ class EmployeeApplication{
|
|||||||
* @param $contractType string
|
* @param $contractType string
|
||||||
*/
|
*/
|
||||||
function updateEmployee($idEmployee, $code, $idEmployeeType, $contractType){
|
function updateEmployee($idEmployee, $code, $idEmployeeType, $contractType){
|
||||||
|
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||||
|
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||||
|
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
|
||||||
|
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("UPDATE employees
|
$stmt = $this->pdo->prepare("UPDATE employees
|
||||||
SET
|
SET
|
||||||
@ -361,7 +383,10 @@ class EmployeeApplication{
|
|||||||
function updateEmployeeData($requestData){
|
function updateEmployeeData($requestData){
|
||||||
// Getting and validating the data
|
// Getting and validating the data
|
||||||
$idEmployee = $requestData['idEmployee'];
|
$idEmployee = $requestData['idEmployee'];
|
||||||
|
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||||
|
|
||||||
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
|
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
|
||||||
|
$this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0");
|
||||||
|
|
||||||
$code = $requestData['code'];
|
$code = $requestData['code'];
|
||||||
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
$this->asserts->isNotEmpty($code, "The code can't be empty.");
|
||||||
@ -390,7 +415,10 @@ class EmployeeApplication{
|
|||||||
$this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters.");
|
$this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters.");
|
||||||
|
|
||||||
$idEmployeeType = $requestData{'idEmployeeType'};
|
$idEmployeeType = $requestData{'idEmployeeType'};
|
||||||
|
$this->asserts->higherThanZero($idEmployeeType, "idEmployeeType must be higher than 0");
|
||||||
|
|
||||||
$contractType = $requestData{'contractType'};
|
$contractType = $requestData{'contractType'};
|
||||||
|
$this->asserts->isNotEmpty($contractType, "The contract type can't be empty.");
|
||||||
|
|
||||||
// Encrypting the sensitive data
|
// Encrypting the sensitive data
|
||||||
$securedFirstName = $this->cryptographyService->encryptString($firstName);
|
$securedFirstName = $this->cryptographyService->encryptString($firstName);
|
||||||
@ -424,6 +452,8 @@ class EmployeeApplication{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function disableEmployeeRecord($idEmployee){
|
function disableEmployeeRecord($idEmployee){
|
||||||
|
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $this->pdo->prepare("UPDATE employees
|
$stmt = $this->pdo->prepare("UPDATE employees
|
||||||
SET
|
SET
|
||||||
@ -467,6 +497,9 @@ class EmployeeApplication{
|
|||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function listAllActiveEmployees(){
|
function listAllActiveEmployees(){
|
||||||
$ids = $this->getIdEmployeeFromAllActiveEmployees();
|
$ids = $this->getIdEmployeeFromAllActiveEmployees();
|
||||||
|
|
||||||
|
@ -45,5 +45,16 @@ class Asserts{
|
|||||||
throw new Exception($errorMessage);
|
throw new Exception($errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $number integer
|
||||||
|
* @param $errorMessage string
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
function higherThanZero($number, $errorMessage){
|
||||||
|
if($number <= 0){
|
||||||
|
throw new Exception($errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user