relationStudentSchool.js 1.2 KB

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const moneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
  5. // 学生档案
  6. const doc = {
  7. is_past: { type: String, default: '0' }, // 往期学员: 0-当期;1-往期
  8. term: { type: String }, // 学期
  9. };
  10. // 学员与学校关系表
  11. const relationStudentSchool = {
  12. student_id: { type: String, required: false, zh: '学员id', ref: 'Student', getProp: [ 'name', 'icon', 'level', 'phone' ] }, //
  13. school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'img_url', 'name', 'phone', 'coach_num', 'student_num', 'address', 'brief' ] }, //
  14. doc: { type: Object, required: false, zh: '档案' }, //
  15. };
  16. const schema = new Schema(relationStudentSchool, { toJSON: { virtuals: true } });
  17. schema.index({ id: 1 });
  18. schema.index({ student_id: 1 });
  19. schema.index({ school_id: 1 });
  20. schema.index({ 'meta.createdAt': 1 });
  21. schema.plugin(metaPlugin);
  22. schema.plugin(moneyPlugin({ zh: '余额' }));
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('RelationStudentSchool', schema, 'relationStudentSchool');
  26. };