school.js 784 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 学校
  5. const school = {
  6. name: { type: String, required: false, zh: '名称' }, //
  7. brief: { type: String, required: false, zh: '简介' }, //
  8. img_url: { type: Array, required: false, zh: '图片' }, //
  9. user_id: { type: String, required: false, zh: '用户表信息', ref: 'User', getProp: [ 'name' ] }, //
  10. };
  11. const schema = new Schema(school, { toJSON: { virtuals: true } });
  12. schema.index({ id: 1 });
  13. schema.index({ 'meta.createdAt': 1 });
  14. schema.index({ name: 1 });
  15. schema.index({ user_id: 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('School', schema, 'school');
  20. };