modules.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * 模块信息
  3. */
  4. 'use strict';
  5. const Schema = require('mongoose').Schema;
  6. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  7. // 模块信息
  8. const SchemaDefine = {
  9. site: { type: String, required: true, maxLength: 64 }, // 归属站点
  10. title: { type: String, required: false, maxLength: 100 }, // 模块名称
  11. type: { type: String, required: false, maxLength: 5 }, // 类型,'content'=>信息内容类型/'list'=>'信息列表'类型,
  12. is_use: { type: String, required: false, maxLength: 5 }, // 是否使用,0=>使用中;1=>已禁止
  13. category: { type: String, required: false, maxLength: 5 }, // 类别
  14. meta: {
  15. createdBy: String, // 创建用户
  16. updatedBy: String, // 修改用户
  17. },
  18. };
  19. const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  20. schema.plugin(metaPlugin);
  21. schema.index({ site: 1 });
  22. schema.index({ 'meta.state': 1 });
  23. schema.index({ 'meta.createdAt': -1 });
  24. schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 });
  25. module.exports = app => {
  26. const { mongoose } = app;
  27. return mongoose.model('ModulesInfo', schema, 'cms_modules');
  28. };