[exam] finish assign and remove

This commit is contained in:
xiaomlove
2021-04-28 01:22:25 +08:00
parent d2e05c812e
commit 034d1c23fb
16 changed files with 988 additions and 34 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
<?php
namespace App\Repositories;
use App\Exceptions\NexusException;
use App\Models\Exam;
use App\Models\ExamProgress;
use App\Models\ExamUser;
@@ -166,17 +167,17 @@ class ExamRepository extends BaseRepository
$exams = $this->listMatchExam($uid);
if ($exams->count() > 1) {
do_log(last_query());
throw new \LogicException("Match exam more than 1.");
throw new NexusException("Match exam more than 1.");
}
$exam = $exams->first();
}
if (!$exam) {
throw new \LogicException("No valid exam.");
throw new NexusException("No valid exam.");
}
$user = User::query()->findOrFail($uid);
$exists = $user->exams()->where('exam_id', $exam->id)->exists();
if ($exists) {
throw new \LogicException("Exam: {$exam->id} already assign to user: {$user->id}");
throw new NexusException("Exam: {$exam->id} already assign to user: {$user->id}");
}
$data = [
'exam_id' => $exam->id,