group.js 1.0 KB

1234567891011121314151617181920212223242526272829
  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. };
  18. const schema = new Schema(GroupSchema, { toJSON: { virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.plugin(metaPlugin);
  21. module.exports = app => {
  22. const { mongoose } = app;
  23. return mongoose.model('Group', schema, 'group');
  24. };