mission.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  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. service: { type: String, required: true }, // 服务
  10. method: { type: String, required: true }, // 方法, get,post,delete...
  11. type: { 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. params: { type: Object, required: false },
  18. status: { type: String, maxLength: 200, default: '0' }, // 状态:0=>未开始;1=>正在进行;2=>已完成;3=>失败
  19. dot: { type: Boolean, default: true }, // 需要提醒
  20. progress: { type: String, required: false, maxLength: 200 },
  21. user: { type: String, required: false, maxLength: 200 }, // 用户,监听指定用户用,没有的话,mq就监听项目
  22. uri: { type: String, required: false }, // 文件/图片等需要地址的地方就放这
  23. tenant: { type: String, required: true }, // 所属项目
  24. remark: { type: String },
  25. };
  26. const schema = new Schema(Mission, { toJSON: { virtuals: true } });
  27. schema.index({ id: 1 });
  28. schema.index({ user: 1 });
  29. schema.plugin(metaPlugin);
  30. module.exports = app => {
  31. const { mongoose } = app;
  32. return mongoose.model('Mission', schema, 'mission');
  33. };