group.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. // 群内成员信息
  5. const Patientinfo = new Schema({
  6. patientid: { type: String, required: false }, // 病人ID
  7. url: { type: String, required: false }, // 头像url
  8. name: { type: String, required: false }, // 病人名称
  9. openid: { type: String, required: false }, // 微信openid
  10. });
  11. Patientinfo.index({ patientid: 1 });
  12. // 群信息表
  13. const GroupSchema = {
  14. doctorid: { type: String, required: true, maxLength: 500 }, // 医生id列表
  15. name: { type: String, required: false, maxLength: 200 }, // 群名称
  16. content: { type: String, required: false }, // 群简介
  17. patients: { type: [ Patientinfo ], select: false }, // 群里人员信息
  18. };
  19. const schema = new Schema(GroupSchema, { toJSON: { virtuals: true } });
  20. schema.index({ doctorid: 1 });
  21. schema.index({ 'meta.createdAt': 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('Group', schema, 'group');
  26. };