12345678910111213141516171819202122232425262728293031323334 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const moment = require('moment');
- const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
- const { Secret } = require('naf-framework-mongoose/lib/model/schema');
- // 管理员表
- const admin = {
- name: { type: String }, // 名称
- phone: { type: String }, // 手机
- passwd: { type: Secret, select: false }, // 注册密码
- openid: { type: String }, // 微信openid
- role: { type: String }, // 角色: 0:超级管理员;1:管理员;2:机构管理员;3:业务管理员
- menus: { type: [ String ] }, // 菜单
- pid: { type: String }, // 上级id
- deptname: { type: String }, // 机构名称
- code: { type: String }, // 邀请码
- isdel: { type: Boolean, default: false }, // 是否删除
- remark: { type: String, maxLength: 200 },
- create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
- };
- const schema = new Schema(admin, { toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ name: 1 });
- schema.index({ phone: 1 });
- schema.index({ role: 1 });
- schema.index({ pid: 1 });
- schema.index({ code: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Admin', schema, 'admin');
- };
|