match.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 = {
  6. belong_id: { type: String, zh: '属于id', ref: 'User', getProp: [ 'name' ] }, // 比赛系统中用户的数据id
  7. type: { type: String, zh: '赛事类别' },
  8. logo: { type: Array, required: true, zh: '比赛logo' }, // 比赛logo
  9. name: { type: String, required: true, zh: '比赛名称' }, // 比赛名称
  10. start_time: { type: String, required: true, zh: '比赛开始时间' }, // 比赛开始时间
  11. end_time: { type: String, required: true, zh: '比赛结束时间' }, // 比赛结束时间
  12. address: { type: String, required: true, zh: '比赛地点' }, // 比赛地点
  13. sign_time: { type: String, required: true, zh: '报名截止时间' }, // 报名截止时间
  14. money_remark: { type: String, required: false, zh: '报名费用说明' }, // 报名费用说明
  15. money_mode: { type: String, required: false, zh: '付款方式' }, // 付款方式
  16. contact: { type: String, required: true, zh: '联系方式' }, // 联系方式
  17. explain: { type: String, required: false, zh: '报名说明' }, // 报名说明
  18. regular: { type: String, required: false, zh: '赛事规程' }, // 赛事规程
  19. status: { type: String, required: true, default: '0', zh: '比赛状态' }, // 字典表中的标签
  20. };
  21. const schema = new Schema(match, { toJSON: { getters: true, virtuals: true } });
  22. schema.index({ id: 1 });
  23. schema.index({ 'meta.createdAt': 1 });
  24. schema.index({ belong_id: 1 });
  25. schema.index({ type: 1 });
  26. schema.index({ name: 1 });
  27. schema.index({ start_time: 1 });
  28. schema.index({ end_time: 1 });
  29. schema.index({ sign_time: 1 });
  30. schema.index({ contact: 1 });
  31. schema.index({ status: 1 });
  32. schema.plugin(metaPlugin);
  33. const source = 'race';
  34. module.exports = app => {
  35. const is_multiple = app.mongooseDB.clients;
  36. let model;
  37. if (is_multiple) {
  38. const conn = app.mongooseDB.get(source);
  39. model = conn.model('Match', schema, 'match');
  40. } else {
  41. const { mongoose } = app;
  42. model = mongoose.model('Match', schema, 'match');
  43. }
  44. return model;
  45. };