mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -1273,52 +1273,6 @@ exports.getUnitByUuid = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// "Quiz (self-enrich for pass_quiz task requirement blocks)" — mirrors
|
||||
// getUnitByUuid/getLessonByUuid's uuid-lookup pattern. A quiz is always
|
||||
// unit-scoped (unit_quizzes.unit_id unique) so access resolves through its
|
||||
// one parent unit, same rule canAccessUnit already implements.
|
||||
exports.getQuizByUuid = async (req, res) => {
|
||||
try {
|
||||
const { uuid } = req.params;
|
||||
const quiz = await UnitQuiz.findOne({
|
||||
where: { uuid, ...notDeleted },
|
||||
attributes: ["quiz_id", "uuid", "title", "is_required", "passing_score"],
|
||||
include: [{
|
||||
model: Unit, as: "unit",
|
||||
attributes: ["unit_id", "uuid", "title"],
|
||||
include: [{
|
||||
model: Course, as: "courses",
|
||||
where: notDeleted, required: false,
|
||||
attributes: ["course_id", "title", "subscription"],
|
||||
through: { attributes: [] },
|
||||
}],
|
||||
}],
|
||||
});
|
||||
if (!quiz) return R.error(res, "Quiz not found.", 404);
|
||||
|
||||
if (!await canAccessUnit(req.user.user_id, quiz.unit.unit_id)) {
|
||||
const first = quiz.unit.courses?.[0] ?? null;
|
||||
return res.status(403).json({
|
||||
status: "error",
|
||||
message: "You do not have access to this quiz.",
|
||||
course: first ? { title: first.title, subscription: first.subscription } : null,
|
||||
});
|
||||
}
|
||||
|
||||
const passedAttempt = await QuizAttempt.findOne({
|
||||
where: { quiz_id: quiz.quiz_id, user_id: req.user.user_id, passed: true },
|
||||
});
|
||||
|
||||
const plain = quiz.toJSON();
|
||||
plain.unit.course = plain.unit.courses?.[0] ?? null; // back-compat singular field
|
||||
plain.has_passed = !!passedAttempt;
|
||||
return R.success(res, "Quiz retrieved.", plain);
|
||||
} catch (err) {
|
||||
console.error("[CLIENT][QUIZ][BY UUID]", err);
|
||||
return R.error(res, "Could not retrieve quiz.", 500);
|
||||
}
|
||||
};
|
||||
|
||||
// "Units → Lessons (returns all data)" — a Unit resolves all of its lesson
|
||||
// content in one call, with or without a parent course.
|
||||
exports.getLessonsByUnitUuid = async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user