user.js 856 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
  6. // 用户表(分站模式)
  7. const user = {
  8. account: { type: String, required: true }, // 账号
  9. password: { type: Secret, select: false }, // 密码
  10. uid: { type: String }, // 关联id,与各自业务有关的用户id
  11. remark: { type: String },
  12. };
  13. const schema = new Schema(user, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  14. schema.index({ id: 1 });
  15. schema.index({ account: 1 });
  16. schema.index({ uid: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.plugin(metaPlugin);
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('User', schema, 'user');
  22. };