[module.professor] PUT now checks for @casLogin to be unique
This commit is contained in:
parent
3e0ccea7df
commit
f3085ec4db
|
@ -85,7 +85,7 @@ class professorController{
|
|||
$prof_repo = Repo::getRepo('professor');
|
||||
|
||||
/* (1) Check if professor already exists */
|
||||
$exists = $prof_repo->exists($lastName, $firstName);
|
||||
$exists = $prof_repo->exists($lastName, $firstName, $casLogin);
|
||||
|
||||
/* (2) If found -> already exists */
|
||||
if( !is_null($exists) )
|
||||
|
@ -159,14 +159,25 @@ class professorController{
|
|||
$initials = null;
|
||||
$isAdmin = null;
|
||||
$casLogin = null;
|
||||
$remCas = false;
|
||||
$remCas = true;
|
||||
extract($args);
|
||||
|
||||
/* Get the professor repo */
|
||||
/** @var professor $prof_repo */
|
||||
$prof_repo = Repo::getRepo('professor');
|
||||
|
||||
/* (1) Try to update */
|
||||
if( !is_null($casLogin) ){
|
||||
|
||||
/* (1) Check if @casLogin already exists */
|
||||
$exists = $prof_repo->getByLogin($casLogin);
|
||||
|
||||
/* (2) If found -> already exists */
|
||||
if( !is_null($exists) )
|
||||
return ['error' => new Error(Err::AlreadyExists)];
|
||||
|
||||
}
|
||||
|
||||
/* (3) Try to update */
|
||||
return ['updated' => $prof_repo->update(
|
||||
$prof_id,
|
||||
$lastName,
|
||||
|
|
|
@ -66,30 +66,33 @@ class professor extends Repo_i {
|
|||
---------------------------------------------------------*/
|
||||
public function exists(string $lastName, string $firstName, ?string $casLogin = null) : ?int{
|
||||
|
||||
/* (1) Prepare Statement */
|
||||
/* (1) Manage if @casLogin given/ignored */
|
||||
$cond = is_null($casLogin) ? '' : 'OR `casLogin` = :casLogin';
|
||||
$parm = is_null($casLogin) ? [] : [':casLogin' => $casLogin];
|
||||
|
||||
/* (2) Prepare Statement */
|
||||
$st = $this->pdo->prepare("SELECT idProfesseur
|
||||
FROM Professeur
|
||||
WHERE firstName = :firstName
|
||||
AND lastName = :lastName
|
||||
".(is_string($casLogin) ? "AND casLogin = :casLogin" : ""));
|
||||
WHERE ( firstName = :firstName AND lastName = :lastName )
|
||||
$cond;");
|
||||
|
||||
/* (2) Bind params and execute */
|
||||
$params = [
|
||||
/* (3) Statement eror */
|
||||
if( is_bool($st) )
|
||||
return NULL;
|
||||
|
||||
/* (4) Bind params and execute */
|
||||
$params = array_merge([
|
||||
':firstName' => $firstName,
|
||||
':lastName' => $lastName
|
||||
];
|
||||
|
||||
if(is_string($casLogin)){
|
||||
$params[":casLogin"] = $casLogin;
|
||||
}
|
||||
], $parm);
|
||||
|
||||
$success = $st->execute();
|
||||
|
||||
/* (3) Return NULL on error */
|
||||
/* (5) Return NULL on error */
|
||||
if( !$success )
|
||||
return NULL;
|
||||
|
||||
/* (4) Return @prof_id or NULL if nothing found */
|
||||
/* (7) Return @prof_id or NULL if nothing found */
|
||||
return $st->fetch()['idProfesseur'] ?: NULL;
|
||||
|
||||
}
|
||||
|
|
|
@ -345,7 +345,7 @@ gstore.add('ic_handler', function(prof_id){
|
|||
|
||||
/* (4.5.2.1) Manage 'already exist' error */
|
||||
if( rs.error == 29 ){
|
||||
gstore.get.create_err = 'Le couple Nom-Prénom est déja utilisé.';
|
||||
gstore.get.create_err = 'Le couple Nom-Prénom ou l\'identifiant sont déja utilisés.';
|
||||
return setTimeout(() => gstore.add('create_err', ''), 2000);
|
||||
}
|
||||
|
||||
|
@ -572,11 +572,18 @@ gstore.add('ie_handler', function(prof_i){
|
|||
/* (5.8.1) Delete professor */
|
||||
api.call('PUT professor/'+prof.idProfesseur, rq, function(rs){
|
||||
|
||||
/* (5.8.1.1) Abort on error */
|
||||
|
||||
/* (5.8.1.1) Manage 'already exist' error */
|
||||
if( rs.error == 29 ){
|
||||
gstore.get.edit_err = 'Le couple Nom-Prénom ou l\'identifiant sont déja utilisés.';
|
||||
return setTimeout(() => gstore.add('edit_err', ''), 2000);
|
||||
}
|
||||
|
||||
/* (5.8.1.2) Abort on error */
|
||||
if( rs.error !== 0 || rs.updated !== true )
|
||||
return reject(rs.error);
|
||||
|
||||
/* (5.8.1.2) Success */
|
||||
/* (5.8.1.3) Success */
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue