diff --git a/server/controllers/staff.php b/server/controllers/staff.php index aafedcbd..c7cf0e91 100644 --- a/server/controllers/staff.php +++ b/server/controllers/staff.php @@ -6,6 +6,7 @@ require_once 'staff/get-tickets.php'; require_once 'staff/get-new-tickets.php'; require_once 'staff/get-all-tickets.php'; require_once 'staff/search-tickets.php'; +require_once 'staff/add.php'; $systemControllerGroup = new ControllerGroup(); $systemControllerGroup->setGroupPath('/staff'); @@ -17,5 +18,6 @@ $systemControllerGroup->addController(new GetTicketStaffController); $systemControllerGroup->addController(new GetNewTicketsStaffController); $systemControllerGroup->addController(new GetAllTicketsStaffController); $systemControllerGroup->addController(new SearchTicketStaffController); +$systemControllerGroup->addController(new AddStaffController); $systemControllerGroup->finalize(); \ No newline at end of file diff --git a/server/controllers/staff/add.php b/server/controllers/staff/add.php new file mode 100644 index 00000000..63183974 --- /dev/null +++ b/server/controllers/staff/add.php @@ -0,0 +1,76 @@ + 'staff_3', + 'requestData' => [ + 'name' => [ + 'validation' => DataValidator::length(2, 55)->alpha(), + 'error' => ERRORS::INVALID_NAME + ], + 'email' => [ + 'validation' => DataValidator::email(), + 'error' => ERRORS::INVALID_EMAIL + ], + 'password' => [ + 'validation' => DataValidator::length(5, 200), + 'error' => ERRORS::INVALID_PASSWORD + ], + 'level' => [ + 'validation' => DataValidator::between(1, 3, true), + 'error' => ERRORS::INVALID_LEVEL + ] + + ] + ]; + } + + public function handler() { + + $this->storeRequestData(); + $staff = new Staff(); + + $staffrow = Staff::getDataStore($this->email,'email'); + + if($staffrow->isNull()) { + $staff->setProperties([ + 'name'=> $this->name, + 'email' => $this->email, + 'password'=> $this->password, + 'profilePic' => $this->profilePic, + 'level' => $this->level, + 'sharedDepartmentList'=> $this->departments, + ]); + + $staff->store(); + + Response::respondSuccess(); + return; + } + + Response::respondError(ERRORS::ALREADY_A_STAFF); + + + } + public function storeRequestData() { + $this->name = Controller::request('name'); + $this->email = Controller::request('email'); + $this->password = Controller::request('password'); + $this->profilePic = Controller::request('profilePic'); + $this->level = Controller::request('level'); + $this->departments = Controller::request('departments'); + } +} \ No newline at end of file diff --git a/server/data/ERRORS.php b/server/data/ERRORS.php index 91387377..f0bd8322 100644 --- a/server/data/ERRORS.php +++ b/server/data/ERRORS.php @@ -26,4 +26,6 @@ class ERRORS { const INVALID_ORDER = 'INVALID_ORDER'; const INVALID_USER = 'INVALID_USER'; const ALREADY_BANNED = 'ALREADY_BANNED'; + const INVALID_LEVEL = 'INVALID_LEVEL'; + const ALREADY_A_STAFF = 'ALREADY_A_STAFF'; }