fix: bypass tenant scope in recalculateScore - null quiz when candidate finishes quiz
This commit is contained in:
@@ -142,12 +142,21 @@ class AttemptController extends Controller
|
|||||||
|
|
||||||
private function recalculateScore(Attempt $attempt)
|
private function recalculateScore(Attempt $attempt)
|
||||||
{
|
{
|
||||||
$attempt->load(['quiz.questions.options', 'answers.option']);
|
// Bypass tenant scope: candidates have no tenant_id
|
||||||
|
$quiz = Quiz::withoutGlobalScopes()
|
||||||
|
->with(['questions.options'])
|
||||||
|
->find($attempt->quiz_id);
|
||||||
|
|
||||||
|
$attempt->load(['answers.option']);
|
||||||
|
|
||||||
$score = 0;
|
$score = 0;
|
||||||
$maxScore = 0;
|
$maxScore = 0;
|
||||||
|
|
||||||
foreach ($attempt->quiz->questions as $question) {
|
if (!$quiz) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($quiz->questions as $question) {
|
||||||
$maxScore += $question->points;
|
$maxScore += $question->points;
|
||||||
$userAnswer = $attempt->answers->where('question_id', $question->id)->first();
|
$userAnswer = $attempt->answers->where('question_id', $question->id)->first();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user