channel.js 1.2 KB

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 科技频道表
  8. const channel = {
  9. user_id: { type: ObjectId }, // 关联的personal的id
  10. title: { type: String, required: false, maxLength: 200 }, // 标题
  11. origin: { type: String, required: false, maxLength: 200 }, // 来源
  12. type: { type: String, required: false, maxLength: 200 }, // 类别
  13. room_id: { type: String, required: false, maxLength: 200 }, // 房间id,服务生成,从2001开始
  14. passwd: { type: Secret, required: false, maxLength: 200, select: false }, // 密码,房间号
  15. desc: { type: String, maxLength: 1000 }, // 简介
  16. remark: { type: String, maxLength: 200 },
  17. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  18. };
  19. const schema = new Schema(channel, { toJSON: { virtuals: true } });
  20. schema.index({ id: 1 });
  21. schema.index({ 'meta.createdAt': 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('Channel', schema, 'channel');
  26. };