1234567891011121314151617181920212223242526272829303132333435363738 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- // 组别项目
- const match_project = {
- match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
- group_id: { type: String, required: true, zh: '赛事分组id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事分组中的组名称
- type: { type: String, required: true, zh: '项目类别' }, // 字典表中的标签
- name: { type: String, required: true, zh: '名称' }, //
- age: { type: String, required: false, zh: '年龄限制' }, // 12-16 / null(不限)
- gender: { type: String, required: false, zh: '性别限制' }, // 字典表中的标签
- num: { type: Number, required: false, zh: '人数限制' }, //
- explain: { type: String, required: false, zh: '说明' }, //
- };
- const schema = new Schema(match_project, { toJSON: { getters: true, virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.index({ match_id: 1 });
- schema.index({ group_id: 1 });
- schema.index({ type: 1 });
- schema.index({ name: 1 });
- schema.plugin(metaPlugin);
- 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('MatchProject', schema, 'matchProject');
- } else {
- const { mongoose } = app;
- model = mongoose.model('MatchProject', schema, 'matchProject');
- }
- return model;
- };
|