'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); // 课程信息表 const lessonInfo = new Schema({ name: { type: String, required: false, maxLength: 500 }, // 名称 teacherid: { type: String, required: false, maxLength: 500 }, // 教师id date: { type: String, required: false, maxLength: 500 }, // 日期 day: { type: String, required: false, maxLength: 500 }, // 课程天数,半天或一天 }); // 课程表 const LessonSchema = { class: { type: String, required: true, maxLength: 500 }, // 班级 term: { type: String, required: true, maxLength: 500 }, // 期 batch: { type: String, required: true, maxLength: 500 }, // 批次 lessons: { type: [ lessonInfo ], select: true }, // 课程信息 }; const schema = new Schema(LessonSchema, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Lesson', schema, 'lesson'); };