Files
ostandari/server/models/News.js
T
2026-06-19 12:26:40 +03:30

66 lines
2.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}`);
}
function attachmentFile(file) {
if (!file) return null;
if (file.startsWith('http://') || file.startsWith('https://')) return file;
return s3Storage.getPublicUrl(`uploads/files/newsAttachments/${file}`);
}
const NewsAttachmentSchema = mongoose.Schema({
file: {type: String, get: attachmentFile},
title: String
})
const NewsSchema = mongoose.Schema({
title: String,
shortTitlePanel: String,
shortTitleFront: String,
summaryTitle: String,
leadTitle: String,
shortSummaryTitle: String,
customDate: {type: Date, default: Date.now},
catId: {type: mongoose.Schema.Types.ObjectId, ref: 'Category'},
allCat: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}],
newsFileId: {type: mongoose.Schema.Types.ObjectId, ref: 'NewsFile'},
rootParent: {type: mongoose.Schema.Types.ObjectId, ref: 'Category'},
priority: {type: Boolean, default: false},
allowComment: {type: Boolean, default: false},
showInHome: {type: Boolean, default: true},
slider: {type: Boolean, default: false},
PublisherId:{type:String},
PublisherAccept:{type:Boolean , default:false},
publish: {type: Boolean, default: false},
pageContent: String,
cover: {type: String, get: image, default: null},
thumbCover: {type: String, get: image, default: null},
content:{type:String , default:''},
userViews: {type: Number, default: 0},
special: {type: Boolean, default: false},
notifications: {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},
keywords: {type: Array, default: []},
metaTagDesc: {type: String, default: null},
newsStatus: {type: Boolean, default: false},
modelType: String,
customDateHistory: Array,
attachments: [NewsAttachmentSchema],
imported: Boolean,
superNews: Boolean
});
NewsSchema.index({catId: 1, allCat: 1});
NewsSchema.plugin(mongoosePaginate);
module.exports = mongoose.model('News', NewsSchema);