dbstructure add duration

This commit is contained in:
xiaomlove
2021-05-06 13:01:17 +08:00
parent a5e7c06fe1
commit 003813feb0
31 changed files with 36 additions and 20 deletions

View File

@@ -27,6 +27,7 @@ class ExamRepository extends BaseRepository
public function store(array $params)
{
$this->checkIndexes($params);
$this->checkBeginEnd($params);
$valid = $this->listValid(null, Exam::DISCOVERED_YES);
if ($valid->isNotEmpty() && $params['status'] == Exam::STATUS_ENABLED) {
throw new NexusException("Enabled and discovered exam already exists.");
@@ -38,6 +39,7 @@ class ExamRepository extends BaseRepository
public function update(array $params, $id)
{
$this->checkIndexes($params);
$this->checkBeginEnd($params);
$valid = $this->listValid($id, Exam::DISCOVERED_YES);
if ($valid->isNotEmpty() && $params['status'] == Exam::STATUS_ENABLED) {
throw new NexusException("Enabled and discovered exam already exists.");
@@ -70,6 +72,18 @@ class ExamRepository extends BaseRepository
return true;
}
private function checkBeginEnd(array $params)
{
if (!empty($params['begin']) && !empty($params['end']) && empty($params['duration'])) {
return true;
}
if (empty($params['begin']) && empty($params['end']) && ctype_digit((string)$params['duration']) && $params['duration'] > 0) {
return true;
}
throw new \InvalidArgumentException("Require begin and end or only duration.");
}
public function getDetail($id)
{
$exam = Exam::query()->findOrFail($id);