diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 988be4f..1b5483a 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -145,7 +145,11 @@ class EmployeeApplication{ $this->asserts->betweenLength($phone, 10, 10, "The phone number must be 10 digits without special characters."); $idEmployeeType = $requestData{'idEmployeeType'}; + $this->asserts->higherThanZero($idEmployeeType, 'idEmployeeType must be higher than zero.'); + $contractType = $requestData{'contractType'}; + $this->asserts->isNotEmpty($contractType, "The contract type can't be empty."); + $this->asserts->existInArray($contractType, $this->settings['contractTypes'], 'The contract type is not a valid one.'); // Encrypting the sensitive data $securedFirstName = $this->cryptographyService->encryptString($firstName); @@ -421,6 +425,7 @@ class EmployeeApplication{ $contractType = $requestData{'contractType'}; $this->asserts->isNotEmpty($contractType, "The contract type can't be empty."); + $this->asserts->existInArray($contractType, $this->settings['contractTypes'], 'The contract type is not a valid one.'); // Encrypting the sensitive data $securedFirstName = $this->cryptographyService->encryptString($firstName); diff --git a/api-payroll/src/service/Asserts.php b/api-payroll/src/service/Asserts.php index 3976a26..d627334 100644 --- a/api-payroll/src/service/Asserts.php +++ b/api-payroll/src/service/Asserts.php @@ -69,5 +69,17 @@ class Asserts{ throw new Exception($errorMessage); } } + + /** + * @param $string string + * @param $array array + * @param $errorMessage string + * @throws Exception + */ + function existInArray($string, $array, $errorMessage){ + if(!in_array($string, $array)){ + throw new Exception($errorMessage); + } + } } ?>