12345678910111213141516171819202122 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const moment = require('moment');
- const metaPlugin = require('naf-framework-mongoose/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, default: moment().format('YYYY-MM-DD HH:mm:ss') },
- };
- 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('Invite_code', schema, 'invite_code');
- };
|