12345678910111213141516171819202122232425262728293031323334 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
- // 用户表
- const user = {
- name: { type: String }, // 姓名
- phone: { type: String }, // 电话
- password: { type: Secret, select: false }, // 密码
- email: { type: String }, // 邮箱
- address: { type: String }, // 地址
- dept: { type: String }, // 部门
- zw: { type: String }, // 职务
- company: { type: String }, // 工作单位
- type: { type: String }, // 类型【0:管理员,1:商户,2:用户】
- openid: { type: String }, // 微信openid
- remark: { type: String },
- };
- const schema = new Schema(user, { toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ name: 1 });
- schema.index({ phone: 1 });
- schema.index({ address: 1 });
- schema.index({ dept: 1 });
- schema.index({ zw: 1 });
- schema.index({ company: 1 });
- schema.index({ openid: 1 });
- schema.index({ type: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('User', schema, 'user');
- };
|