matchProject.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 组别项目
  5. const match_project = {
  6. match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
  7. group_id: { type: String, required: true, zh: '赛事分组id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事分组中的组名称
  8. type: { type: String, required: true, zh: '项目类别' }, // 字典表中的标签
  9. name: { type: String, required: true, zh: '名称' }, //
  10. age: { type: String, required: false, zh: '年龄限制' }, // 12-16 / null(不限)
  11. gender: { type: String, required: false, zh: '性别限制' }, // 字典表中的标签
  12. num: { type: Number, required: false, zh: '人数限制' }, //
  13. explain: { type: String, required: false, zh: '说明' }, //
  14. };
  15. const schema = new Schema(match_project, { toJSON: { getters: true, virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.index({ match_id: 1 });
  19. schema.index({ group_id: 1 });
  20. schema.index({ type: 1 });
  21. schema.index({ name: 1 });
  22. schema.plugin(metaPlugin);
  23. const source = 'race';
  24. module.exports = app => {
  25. const is_multiple = app.mongooseDB.clients;
  26. let model;
  27. if (is_multiple) {
  28. const conn = app.mongooseDB.get(source);
  29. model = conn.model('MatchProject', schema, 'matchProject');
  30. } else {
  31. const { mongoose } = app;
  32. model = mongoose.model('MatchProject', schema, 'matchProject');
  33. }
  34. return model;
  35. };