/** * 新闻信息 */ 'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); // 附件信息 const Attachment = new Schema({ name: { type: String, maxLength: 128 }, uri: { type: String, maxLength: 128 }, }, { _id: false }); // 新闻信息 const SchemaDefine = { site: { type: String, required: true, maxLength: 64 }, // 分站 title: { type: String, required: false, maxLength: 128 }, // 标题 pic: { type: String, required: false, maxLength: 256 }, // 标题图片URL content: { type: String, required: false, maxLength: 102400, select: false }, // 内容详情 type: { type: String, required: false, maxLength: 5 }, // 所属类型 parent_id: { type: String, required: false, maxLength: 64 }, // 所属id parent: { type: String, required: false, maxLength: 100 }, // 所属名称 publish_time: String, // 发布时间 attachment: [ Attachment ], // 附件 is_use: { type: String, required: false, maxLength: 5 }, // 是否使用,0=>使用中;1=>已禁止 meta: { createdBy: String, // 创建用户 updatedBy: String, // 修改用户 }, }; const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } }); schema.plugin(metaPlugin); schema.index({ site: 1 }); schema.index({ 'meta.state': 1 }); schema.index({ 'meta.createdAt': -1 }); schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 }); module.exports = app => { const { mongoose } = app; return mongoose.model('NewsInfo', schema, 'cms_news'); };