question.js 746 B

1234567891011121314151617181920
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const { ObjectId } = require('mongoose').Types;
  5. // 题目表
  6. const question = {
  7. title: { type: String }, // 题目
  8. type: { type: String }, // 类型
  9. selects: { type: Array }, // 选项: {label,value,isRight:Boolean, true:正确/false:错误}
  10. remark: { type: String },
  11. times: { type: Number, default: 0 }, // 出题次数
  12. };
  13. const schema = new Schema(question, { toJSON: { virtuals: true } });
  14. schema.index({ id: 1 });
  15. schema.index({ 'meta.createdAt': 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('Question', schema, 'question');
  20. };