123456789101112131415161718192021222324252627282930313233343536 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const moment = require('moment');
- const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
- const { ObjectId } = require('mongoose').Types;
- // 新闻表
- const news = {
- user_id: { type: ObjectId },
- column_name: { type: String }, // 栏目名称
- title: { type: String }, // 标题
- release_time: { type: String }, // 发布时间
- origin: { type: String }, // 来源
- content: { type: String }, // 内容
- image: { type: Array }, // 图片
- fileUrl: { type: Array }, // 附件
- remark: { type: String },
- create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
- };
- const image = {
- name: { type: String, zh: '名称' },
- url: { type: String, zh: '地址' },
- };
- const schema = new Schema(news, { toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ user_id: 1 });
- schema.index({ column_name: 1 });
- schema.index({ origin: 1 });
- schema.index({ title: 1 });
- schema.index({ release_time: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('News', schema, 'news');
- };
|