You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.0 KiB
47 lines
1.0 KiB
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); |