tenant.js 786 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/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. is_use: { type: Boolean, default: true }, // 是否使用
  11. remark: { type: String },
  12. };
  13. const schema = new Schema(tenant, { toJSON: { virtuals: true } });
  14. schema.index({ id: 1 });
  15. schema.index({ _tenant: 1 });
  16. schema.index({ name: 1 });
  17. schema.index({ is_use: 1 });
  18. schema.index({ 'meta.createdAt': 1 });
  19. schema.plugin(metaPlugin);
  20. module.exports = app => {
  21. const { mongoose } = app;
  22. return mongoose.model('Tenant', schema, 'tenant');
  23. };