1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
- // 比赛信息
- const match = {
- belong_id: { type: String, zh: '属于id', ref: 'Race.User', getProp: [ 'name', 'user_id.name' ] }, // 比赛系统中用户的数据id
- type: { type: String, zh: '赛事类别' },
- logo: { type: Array, required: true, zh: '比赛logo' }, // 比赛logo
- name: { type: String, required: true, zh: '比赛名称' }, // 比赛名称
- start_time: { type: String, required: true, zh: '比赛开始时间' }, // 比赛开始时间
- end_time: { type: String, required: true, zh: '比赛结束时间' }, // 比赛结束时间
- address: { type: String, required: true, zh: '比赛地点' }, // 比赛地点
- sign_time: { type: String, required: true, zh: '报名截止时间' }, // 报名截止时间
- money_remark: { type: String, required: false, zh: '报名费用说明' }, // 报名费用说明
- money_mode: { type: String, required: false, zh: '付款方式' }, // 付款方式
- contact: { type: String, required: true, zh: '联系方式' }, // 联系方式
- explain: { type: String, required: false, zh: '报名说明' }, // 报名说明
- regular: { type: String, required: false, zh: '赛事规程' }, // 赛事规程
- status: { type: String, required: true, default: '0', zh: '比赛状态' }, // 字典表中的标签
- format: { type: String, zh: '赛事赛制' },
- };
- const schema = new Schema(match, { toJSON: { getters: true, virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.index({ belong_id: 1 });
- schema.index({ type: 1 });
- schema.index({ name: 1 });
- schema.index({ start_time: 1 });
- schema.index({ end_time: 1 });
- schema.index({ sign_time: 1 });
- schema.index({ contact: 1 });
- schema.index({ status: 1 });
- schema.plugin(metaPlugin);
- schema.plugin(MoneyPlugin({ zh: '金额', required: false }));
- 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('Match', schema, 'match');
- } else {
- const { mongoose } = app;
- model = mongoose.model('Match', schema, 'match');
- }
- return model;
- };
|