Professional Documents
Culture Documents
Đáp Án
Đáp Án
Câu 1:
Sinh viên tạo được schema như dưới đây được 2 điểm :
Câu 2.
Run chạy route GET/quizzes -> danh sách các news (0.5 điểm)
Run chạy route POST/questions -> tạo 1 document thành công vào News Schema (0.5 điểm)
Run chạy route PUT/news -> thông báo k hỗ trợ và mã lỗi 403 (0.25 điểm)
Run chạy route DELETE/news -> delete 1 document thành công vào News Schema (0.25 điểm)
Câu 3:
quizRouter.route('/:quizId/populate')
.get( function (req, res, next) {
const quizId = req.params.quizId;
Quiz.findOne({ _id: quizId })
.populate({
path: 'questions',
match: { text: { $regex: /capital/i } } // Example
filter condition
})
.exec((err, quiz) => {
if (err) {
console.error("Error finding quiz:", err);
res.status(500).json({ error: 'Internal Server
Error' });
} else if (!quiz) {
res.status(404).json({ error: 'Quiz not found' });
} else {
res.json(quiz);
}
});
});
Câu 4: Thực hiện được xác thực token + 2 điểm
{
text: "What is the capital of France?",
options: ["Paris", "London", "Berlin", "Madrid"],
correctAnswerIndex: 0,
quizId: savedQuiz._id
},
{
text: "Who developed the theory of relativity?",
options: ["Albert Einstein", "Isaac Newton", "Galileo Galilei", "Nikola
Tesla"],
correctAnswerIndex: 0,
quizId: savedQuiz._id
},
{
text: "What is the symbol for iron on the periodic table?",
options: ["Fe", "I", "Au", "Ag"],
correctAnswerIndex: 0,
quizId: savedQuiz._id
}
{
"text": "What is the capital of France?",
"options": ["Paris", "London", "Berlin", "Madrid"],
"correctAnswerIndex": 0
{
"text": "Who developed the theory of relativity?",
"options": ["Albert Einstein", "Isaac Newton", "Galileo Galilei", "Nikola Tesl
a"],
"correctAnswerIndex": 0