diff --git a/server/controllers/system.php b/server/controllers/system.php index a6a35f37..b815bca7 100644 --- a/server/controllers/system.php +++ b/server/controllers/system.php @@ -5,6 +5,7 @@ require_once 'system/edit-settings.php'; require_once 'system/add-department.php'; require_once 'system/edit-department.php'; require_once 'system/delete-department.php'; +require_once 'system/get-logs.php'; $systemControllerGroup = new ControllerGroup(); $systemControllerGroup->setGroupPath('/system'); @@ -15,6 +16,6 @@ $systemControllerGroup->addController(new EditSettingsController); $systemControllerGroup->addController(new AddDepartmentController); $systemControllerGroup->addController(new EditDepartmentController); $systemControllerGroup->addController(new DeleteDepartmentController); - +$systemControllerGroup->addController(new GetLogsController); $systemControllerGroup->finalize(); \ No newline at end of file diff --git a/server/controllers/system/get-logs.php b/server/controllers/system/get-logs.php index f459f9bf..52f0224b 100644 --- a/server/controllers/system/get-logs.php +++ b/server/controllers/system/get-logs.php @@ -18,5 +18,8 @@ class GetLogsController extends Controller { public function handler() { $page =Controller::request('page'); + $logList = Log::find('LIMIT ? OFFSET ?', [10, 10*($page-1)+1]); + + Response::respondSuccess($logList->toArray()); } } \ No newline at end of file diff --git a/server/models/Log.php b/server/models/Log.php index e3abd90f..88bdd3f2 100644 --- a/server/models/Log.php +++ b/server/models/Log.php @@ -7,7 +7,7 @@ class Log extends DataStore { public static function getProps() { return [ 'type', - 'author', + 'authorUser', 'authorStaff', 'to' ]; @@ -20,10 +20,17 @@ class Log extends DataStore { $log->setProperties(array( 'type' => $type, - 'author' => (!$author->isNull() && !$author->staff) ? $author : null, + 'authorUser' => (!$author->isNull() && !$author->staff) ? $author : null, 'authorStaff' => (!$author->isNull() && $author->staff) ? $author : null, 'to' => $to, )); $log->store(); } + public function toArray() { + return [ + 'type' => $this->type, + 'to' => $this->to, + 'author' => ($this->authorUser) ? $this->authorUser->toArray() : $this->authorStaff->toArray() + ]; + } } \ No newline at end of file diff --git a/tests/scripts.rb b/tests/scripts.rb index 3eb973e0..a367228a 100644 --- a/tests/scripts.rb +++ b/tests/scripts.rb @@ -7,7 +7,7 @@ class Scripts }) if response['status'] === 'fail' - raise 'Could not create user' + raise response['message'] end end