mission.js 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const moment = require('moment');
  3. const Schema = require('mongoose').Schema;
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. // params不做限制,方便扩展,Object就行
  6. const params = {
  7. project: { type: String, required: true }, // 项目名称(需要设置好,然后找对应路由前置)
  8. router: { type: String, required: true }, // 要执行的路由
  9. method: { type: String, required: true }, // 方法, get,post,delete...
  10. type: { type: String, required: false }, // 类型,需要怎么处理;例如,文件,需要下载
  11. uri: { type: String, required: false }, // 文件/图片等需要地址的地方就放这
  12. body: { type: [ Object, Array ] },
  13. query: { type: Object },
  14. };
  15. const Mission = {
  16. title: { type: String, required: true, maxLength: 200 }, // 教师
  17. create_time: { type: String, required: false, maxLength: 200, default: moment().format('YYYY-MM-DD HH:SS:mm') }, // 创建时间
  18. params: { type: Object, required: false },
  19. status: { type: String, maxLength: 200, default: '0' }, // 状态:0=>未开始;1=>正在进行;2=>已完成;3=>失败
  20. dot: { type: Boolean, default: true }, // 需要提醒
  21. progress: { type: String, required: false, maxLength: 200 },
  22. };
  23. const schema = new Schema(Mission, { toJSON: { virtuals: true } });
  24. schema.index({ id: 1 });
  25. schema.plugin(metaPlugin);
  26. module.exports = app => {
  27. const { mongoose } = app;
  28. return mongoose.model('Mission', schema, 'mission');
  29. };