material.js 866 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. // 上传资料表
  5. const MaterialSchema = {
  6. title: { type: String, required: true, maxLength: 200 }, // 标题
  7. url: { type: String, required: true, maxLength: 200 }, // 资料链接
  8. type: { type: String, required: true, maxLength: 200 }, // 资料类型,0-学生学习资料,1-教师学习资料
  9. content: { type: String, required: false, maxLength: 2000 }, // 简介
  10. tags: [ String ], // 标签
  11. score: { type: String, required: false, maxLength: 200 }, // 资料得分
  12. };
  13. const schema = new Schema(MaterialSchema, { toJSON: { virtuals: true } });
  14. schema.index({ id: 1 });
  15. schema.plugin(metaPlugin);
  16. module.exports = app => {
  17. const { mongoose } = app;
  18. return mongoose.model('Material', schema, 'material');
  19. };