opensupports/server/controllers/system/add-department.php
Guillermo Giuliana 791e0969e9
add script and change 4.7.0 to 4.8.0 (#848)
* add script and change 4.7.0 to 4.8

* change end of line 4.8.0 script

* Delete main.py
2020-07-22 07:32:18 -03:00

59 lines
1.3 KiB
PHP
Executable File

<?php
use Respect\Validation\Validator as DataValidator;
/**
* @api {post} /system/add-department Add department
* @apiVersion 4.8.0
*
* @apiName Add department
*
* @apiGroup System
*
* @apiDescription This path create a new department.
*
* @apiPermission staff3
*
* @apiParam {String} name Name of the new department.
* @apiParam {Boolean} private Indicates if the deparment is not shown to users.
*
* @apiUse NO_PERMISSION
*
* @apiSuccess {Object} data Empty object
*
*/
class AddDepartmentController extends Controller {
const PATH = '/add-department';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_3',
'requestData' => [
'name' => [
'validation' => DataValidator::notBlank()->length(2, 100),
'error' => ERRORS::INVALID_NAME
]
]
];
}
public function handler() {
$name = Controller::request('name');
$private = Controller::request('private');
$departmentInstance = new Department();
$departmentInstance->setProperties([
'name' => $name ,
'private' => $private ? 1 : 0
]);
$departmentInstance->store();
Log::createLog('ADD_DEPARTMENT', $name);
Response::respondSuccess();
}
}