user.js 905 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { ObjectId } = require('mongoose').Types;
  6. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  7. // 管理员表
  8. const user = {
  9. name: { type: String }, // 名称
  10. login_id: { type: String }, // 登陆口令
  11. password: { type: Secret, select: false }, // 注册密码
  12. openid: { type: String }, // 微信openid
  13. remark: { type: String, maxLength: 200 },
  14. create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
  15. };
  16. const schema = new Schema(user, { toJSON: { virtuals: true } });
  17. schema.index({ id: 1 });
  18. schema.index({ 'meta.createdAt': 1 });
  19. schema.plugin(metaPlugin);
  20. module.exports = app => {
  21. const { mongoose } = app;
  22. return mongoose.model('User', schema, 'user');
  23. };