diff --git a/Result.js b/Result.js new file mode 100644 index 0000000..fc19f27 --- /dev/null +++ b/Result.js @@ -0,0 +1,49 @@ +const mongoose = require('mongoose'); + +const answerSchema = new mongoose.Schema({ + questionId: { + type: mongoose.Schema.Types.ObjectId, + required: true + }, + userAnswer: mongoose.Schema.Types.Mixed, + isCorrect: { + type: Boolean, + required: true + }, + score: { + type: Number, + required: true + } +}); + +const resultSchema = new mongoose.Schema({ + exam: { + type: mongoose.Schema.Types.ObjectId, + ref: 'Exam', + required: true + }, + user: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User', + required: true + }, + answers: [answerSchema], + totalScore: { + type: Number, + required: true + }, + maxScore: { + type: Number, + required: true + }, + timeTaken: { // 用时(秒) + type: Number, + required: true + }, + submittedAt: { + type: Date, + default: Date.now + } +}); + +module.exports = mongoose.model('Result', resultSchema); \ No newline at end of file