'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const { ObjectId } = require('mongoose').Types; // 邀请码表 const invite_code = { code: { type: String, required: true, unique: true }, // 邀请码 user_id: { type: ObjectId, required: true }, // 用户id user_name: { type: String }, // 用户名 remark: { type: String, maxLength: 200 }, create_time: { type: String }, }; const schema = new Schema(invite_code, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ code: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('InviteCode', schema, 'inviteCode'); };