match.js 2.3 KB

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