|
@@ -0,0 +1,33 @@
|
|
|
+'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: '用户类别' },
|
|
|
+ parent_id: { type: String, required: false, zh: '所属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;
|
|
|
+};
|