lesson.js 1.1 KB

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 课程表
  5. const lesson = {
  6. school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
  7. coach_id: { type: String, required: false, zh: '教练id', ref: 'Coach', getProp: [ 'name' ] }, //
  8. title: { type: String, zh: '标题' },
  9. class_hour: { type: Number, required: false, zh: '课时' }, //
  10. money: { type: Number, required: false, zh: '金额' }, //
  11. student: { type: Array, ref: 'Student', getProp: [ 'name' ], zh: '学员' },
  12. type: { type: String, required: false, zh: '类型' }, // 0-公开课;1-私教课
  13. };
  14. const schema = new Schema(lesson, { toJSON: { virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.index({ 'meta.createdAt': 1 });
  17. schema.index({ school_id: 1 });
  18. schema.index({ title: 1 });
  19. schema.index({ coach_id: 1 });
  20. schema.index({ type: 1 });
  21. schema.plugin(metaPlugin);
  22. module.exports = app => {
  23. const { mongoose } = app;
  24. return mongoose.model('Lesson', schema, 'lesson');
  25. };