From e8a0fc873cea24faef2443b26fdfa1b14121ede1 Mon Sep 17 00:00:00 2001 From: phgkfux43 <3469266505@qq.com> Date: Sat, 26 Apr 2025 22:38:48 +0800 Subject: [PATCH] ADD file via upload --- Exam.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Exam.js 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