group.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. // 学生信息表
  5. const stuInfo = new Schema({
  6. stuid: { type: String, required: false, maxLength: 500 }, // 学生id
  7. stuname: { type: String, required: false, maxLength: 500 }, // 学生姓名
  8. });
  9. // 分组表
  10. const GroupSchema = {
  11. name: { type: String, required: true, maxLength: 500 }, // 名称
  12. termid: { type: String, required: false, maxLength: 500 }, // 期id
  13. batchid: { type: String, required: false, maxLength: 500 }, // 批次id
  14. classid: { type: String, required: false, maxLength: 500 }, // 班级id
  15. students: { type: [ stuInfo ], select: true }, // 学生信息
  16. score: { type: String, required: false, maxLength: 500 }, // 分数
  17. status: { type: String, required: true, maxLength: 500, default: '0' }, // 状态,0-未确认,1-确认
  18. };
  19. const schema = new Schema(GroupSchema, { toJSON: { virtuals: true } });
  20. schema.index({ id: 1 });
  21. schema.plugin(metaPlugin);
  22. module.exports = app => {
  23. const { mongoose } = app;
  24. return mongoose.model('Group', schema, 'group');
  25. };