lesson.js 1.4 KB

123456789101112131415161718192021222324252627282930
  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 lesson = {
  7. school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
  8. title: { type: String, required: false, zh: '课程标题' }, //
  9. time_start: { type: String, required: false, zh: '开始上课时间' }, //
  10. time_end: { type: String, required: false, zh: '结束时间' }, //
  11. limit: { type: Number, zh: '人数上限' },
  12. refund_hour: { type: String, zh: '退款期限' },
  13. type: { type: String, required: false, zh: '课程类型', default: '0' }, // 0:公开课;1私教课
  14. status: { type: String, required: false, zh: '状态', default: '0' }, // 0-准备中;1-报名中;2-报名结束;3-已开课;4-已结课;-1-停课
  15. brief: { type: String, required: false, zh: '简介' }, //
  16. };
  17. const schema = new Schema(lesson, { toJSON: { virtuals: true } });
  18. schema.index({ id: 1 });
  19. schema.index({ 'meta.createdAt': 1 });
  20. schema.index({ school_id: 1 });
  21. schema.index({ time_start: 1 });
  22. schema.index({ time_end: 1 });
  23. schema.plugin(metaPlugin);
  24. schema.plugin(moneyPlugin({ zh: '金额' }));
  25. module.exports = app => {
  26. const { mongoose } = app;
  27. return mongoose.model('Lesson', schema, 'lesson');
  28. };