123456789101112131415161718192021222324 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
- const { Secret } = require('naf-framework-mongoose/lib/model/schema');
- const User = {
- name: { type: String, required: true, maxLength: 200 }, // 用户名
- login_id: { type: String, required: true, maxLength: 200 }, // 登陆id
- role: { type: String, required: false, maxLength: 200 }, // 角色
- password: { type: Secret, select: false },
- status: { type: String, default: '0' }, // 使用状态: 0=>使用中;1=>冻结;2=>异常
- params: { type: Object }, // 参数字段,需要就用,不需要就不用
- };
- const schema = new Schema(User, { 'multi-tenancy': true, toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.plugin(metaPlugin);
- schema.index({ _tenant: 1 });
- schema.index({ name: 1 });
- schema.index({ login_id: 1 });
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Users', schema, 'user');
- };
|