[module.professor] PUT|POST check for lastName+firstName or casLogin to be unique

This commit is contained in:
xdrm-brackets 2018-03-13 11:44:33 +01:00
parent f3085ec4db
commit 5a050dbbd1
2 changed files with 49 additions and 3 deletions

View File

@ -84,13 +84,29 @@ class professorController{
/** @var professor $prof_repo */
$prof_repo = Repo::getRepo('professor');
/* (1) Check if professor already exists */
/* (1) Check for unique field to be unique
---------------------------------------------------------*/
/* (1) Check @firstName + @lastName */
$exists = $prof_repo->exists($lastName, $firstName, $casLogin);
/* (2) If found -> already exists */
if( !is_null($exists) )
return ['error' => new Error(Err::AlreadyExists)];
/* (3) if @casLogin -> check unique */
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) Else try to create */
$repo_rtn = $prof_repo->create(
$lastName,
@ -166,10 +182,40 @@ class professorController{
/** @var professor $prof_repo */
$prof_repo = Repo::getRepo('professor');
/* (1) If @casLogin -> check unique
---------------------------------------------------------*/
if( !is_null($casLogin) ){
/* (1) Check if @casLogin already exists */
$exists = $prof_repo->getByLogin($casLogin);
$exists_cas = $prof_repo->getByLogin($casLogin);
/* (2) If found -> already exists */
if( !is_null($exists_cas) )
return ['error' => new Error(Err::AlreadyExists)];
}
/* (2) If @lastName or @firstName -> check unique
---------------------------------------------------------*/
if( !is_null($firstName) || !is_null($lastName) ){
/* (1) Try to fetch @prof_id data */
$fetched = $prof_repo->get($prof_id);
/* (2) Error if cannot find */
if( count($fetched) < 1 )
return ['error' => new Error(Err::NoMatchFound)];
/* (3) Extract @firstName + @lastName */
$names = [
'lastName' => is_null($lastName) ? $fetched[0]['lastName'] : $lastName,
'firstName' => is_null($firstName) ? $fetched[0]['firstName'] : $firstName
];
/* (4) Check if exists */
$exists = $prof_repo->exists($names['lastName'], $names['firstName']);
/* (2) If found -> already exists */
if( !is_null($exists) )

View File

@ -86,7 +86,7 @@ class professor extends Repo_i {
':lastName' => $lastName
], $parm);
$success = $st->execute();
$success = $st->execute($params);
/* (5) Return NULL on error */
if( !$success )