ground.js 788 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const { ObjectId } = require('mongoose').Types;
  5. const source = 'race';
  6. // 表
  7. const ground = {
  8. name: { type: String, zh: '场地名' },
  9. remark: { type: String },
  10. };
  11. const schema = new Schema(ground, { toJSON: { virtuals: true } });
  12. schema.index({ id: 1 });
  13. schema.index({ 'meta.createdAt': 1 });
  14. schema.plugin(metaPlugin);
  15. module.exports = app => {
  16. const is_multiple = app.mongooseDB.clients;
  17. let model;
  18. if (is_multiple) {
  19. const conn = app.mongooseDB.get(source);
  20. model = conn.model('Ground', schema, 'ground');
  21. } else {
  22. const { mongoose } = app;
  23. model = mongoose.model('Ground', schema, 'ground');
  24. }
  25. return model;
  26. };