diff --git a/Exam.js b/Exam.js new file mode 100644 index 0000000..ecc5fba --- /dev/null +++ b/Exam.js @@ -0,0 +1,47 @@ +const mongoose = require('mongoose'); + +const questionSchema = new mongoose.Schema({ + type: { + type: String, + enum: ['single', 'multiple', 'text'], + required: true + }, + question: { + type: String, + required: true + }, + options: [String], + answer: mongoose.Schema.Types.Mixed, // 可以是索引、索引数组或字符串 + score: { + type: Number, + required: true + } +}); + +const examSchema = new mongoose.Schema({ + title: { + type: String, + required: true + }, + description: String, + duration: { // 考试时长(分钟) + type: Number, + required: true + }, + questions: [questionSchema], + createdBy: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User', + required: true + }, + createdAt: { + type: Date, + default: Date.now + }, + isActive: { + type: Boolean, + default: true + } +}); + +module.exports = mongoose.model('Exam', examSchema); \ No newline at end of file