tenant.js 915 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  5. const { ObjectId } = require('mongoose').Types;
  6. // 表
  7. const tenant = {
  8. _tenant: { type: String, require: true }, // 站点
  9. name: { type: String }, // 站点名称
  10. params: { type: Object }, // 参数
  11. is_use: { type: Boolean, default: true }, // 是否使用
  12. img: { type: Object }, // 图片设置
  13. menus: { type: Array }, // 分站的权限菜单
  14. remark: { type: String },
  15. };
  16. const schema = new Schema(tenant, { toJSON: { virtuals: true } });
  17. schema.index({ id: 1 });
  18. schema.index({ _tenant: 1 });
  19. schema.index({ name: 1 });
  20. schema.index({ is_use: 1 });
  21. schema.index({ 'meta.createdAt': 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('Tenant', schema, 'tenant');
  26. };