invite_code.js 864 B

12345678910111213141516171819202122
  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. // 邀请码表
  7. const invite_code = {
  8. code: { type: String, required: true, unique: true }, // 邀请码
  9. user_id: { type: ObjectId, required: true }, // 用户id
  10. user_name: { type: String }, // 用户名
  11. remark: { type: String, maxLength: 200 },
  12. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  13. };
  14. const schema = new Schema(invite_code, { toJSON: { virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.index({ code: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.plugin(metaPlugin);
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('Invite_code', schema, 'invite_code');
  22. };