match.js 1.9 KB

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