34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const mongoosePaginate = require('mongoose-paginate-v2');
|
|
const s3Storage = require('../plugins/s3Storage');
|
|
|
|
function image(img) {
|
|
if (!img) return '/img/no-cover.jpg';
|
|
if (img.startsWith('http://') || img.startsWith('https://')) return img;
|
|
return s3Storage.getPublicUrl(`uploads/images/news/${img}`);
|
|
}
|
|
|
|
const NewsFileSchema = mongoose.Schema({
|
|
title: String,
|
|
description: String,
|
|
index: {type: Number, default: null},
|
|
catId: {type: mongoose.Schema.Types.ObjectId, ref: 'Category'},
|
|
allCat: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}],
|
|
rootParent: {type: mongoose.Schema.Types.ObjectId, ref: 'Category'},
|
|
showInHome: {type: Boolean, default: true},
|
|
showInMenu: {type: Boolean, default: false},
|
|
_creator: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
|
_updatedBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
|
siteMap: {type: Boolean, default: true},
|
|
userViews: {type: Number, default: 0},
|
|
modelType: String,
|
|
publish: {type: Boolean, default: true},
|
|
cover: {type: String, get: image, default: null},
|
|
thumbCover: {type: String, get: image, default: null},
|
|
});
|
|
|
|
NewsFileSchema.plugin(mongoosePaginate);
|
|
|
|
|
|
module.exports = mongoose.model('NewsFile', NewsFileSchema);
|