group.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  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. type: { type: String, required: false, maxLength: 500, default: '0' }, // 类型,0-组员,1-组长
  9. });
  10. // 分组表
  11. const GroupSchema = {
  12. name: { type: String, required: true, maxLength: 500 }, // 名称
  13. termid: { type: String, required: false, maxLength: 500 }, // 期id
  14. batchid: { type: String, required: false, maxLength: 500 }, // 批次id
  15. classid: { type: String, required: false, maxLength: 500 }, // 班级id
  16. students: { type: [ stuInfo ], select: true }, // 学生信息
  17. score: { type: String, required: false, maxLength: 500 }, // 分数
  18. status: { type: String, required: true, maxLength: 500, default: '0' }, // 状态,0-未确认,1-确认
  19. };
  20. const schema = new Schema(GroupSchema, { toJSON: { virtuals: true } });
  21. schema.index({ id: 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('Group', schema, 'group');
  26. };