[add] Updating the employee table
This commit is contained in:
parent
63a7186464
commit
57ee1fbd72
@ -301,14 +301,41 @@ class EmployeeApplication{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $idEmployee integer
|
||||||
|
* @param $code string
|
||||||
|
* @param $idEmployeeType integer
|
||||||
|
* @param $contractType string
|
||||||
|
*/
|
||||||
|
function updateEmployee($idEmployee, $code, $idEmployeeType, $contractType){
|
||||||
|
try {
|
||||||
|
$stmt = $this->pdo->prepare("UPDATE employees
|
||||||
|
SET
|
||||||
|
idEmployeeType = :idEmployeeType,
|
||||||
|
code = :code,
|
||||||
|
contractType = :contractType
|
||||||
|
WHERE
|
||||||
|
id = :idEmployee");
|
||||||
|
$this->pdo->beginTransaction();
|
||||||
|
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':code' => $code, ':contractType' => $contractType,
|
||||||
|
':idEmployee' => $idEmployee));
|
||||||
|
$this->pdo->commit();
|
||||||
|
|
||||||
|
$stmt = null;
|
||||||
|
} catch( PDOExecption $e ) {
|
||||||
|
$this->pdo->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $requestData object
|
* @param $requestData object
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function updateEmployee($requestData){
|
function updateEmployeeData($requestData){
|
||||||
// Getting and validating the data
|
// Getting and validating the data
|
||||||
$idEmployee = $requestData['idEmployee'];
|
$idEmployee = $requestData['idEmployee'];
|
||||||
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
|
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
|
||||||
|
$code = $requestData['code'];
|
||||||
|
|
||||||
$firstName = $requestData['firstName'];
|
$firstName = $requestData['firstName'];
|
||||||
$this->asserts->firstName($firstName);
|
$this->asserts->firstName($firstName);
|
||||||
@ -346,6 +373,8 @@ class EmployeeApplication{
|
|||||||
$this->updatePerson($idPerson, $securedFirstName, $securedMiddleName, $securedLastName,
|
$this->updatePerson($idPerson, $securedFirstName, $securedMiddleName, $securedLastName,
|
||||||
$birthDate, $securedEmail, $phone);
|
$birthDate, $securedEmail, $phone);
|
||||||
|
|
||||||
|
$this->updateEmployee($idEmployee, $code, $idEmployeeType, $contractType);
|
||||||
|
|
||||||
$response = array(
|
$response = array(
|
||||||
"fullName" => "$firstName $middleName $lastName",
|
"fullName" => "$firstName $middleName $lastName",
|
||||||
"idEmployee" => $idEmployee,
|
"idEmployee" => $idEmployee,
|
||||||
|
@ -54,7 +54,7 @@ $app->put('/api/employee', function ($request, $response) {
|
|||||||
|
|
||||||
return $response->withStatus(200)
|
return $response->withStatus(200)
|
||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->write(json_encode($this->employeeApplication->updateEmployee($requestData)));
|
->write(json_encode($this->employeeApplication->updateEmployeeData($requestData)));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user