'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); // 用户表 const user = { openid: { type: String, required: false, zh: '微信id' }, // user_id: { type: String, required: false, zh: '用户id', ref: 'Base.User' }, // type: { type: String, required: false, default: '0', zh: '用户类别' }, // 0:普通用户;-1:超级管理员;1比赛管理员;2裁判 parent_id: { type: String, required: false, zh: '所属id' }, // 裁判需要填写管理员的数据id }; const schema = new Schema(user, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ openid: 1 }); schema.index({ user_id: 1 }); schema.index({ type: 1 }); schema.index({ parent_id: 1 }); schema.plugin(metaPlugin); const source = 'race'; module.exports = app => { const is_multiple = app.mongooseDB.clients; let model; if (is_multiple) { const conn = app.mongooseDB.get(source); model = conn.model('User', schema, 'user'); } else { const { mongoose } = app; model = mongoose.model('User', schema, 'user'); } return model; };