28 lines
908 B
JavaScript
28 lines
908 B
JavaScript
const mongoose = require('mongoose');
|
|
const mongoosePaginate = require('mongoose-paginate-v2');
|
|
const s3Storage = require('../plugins/s3Storage');
|
|
|
|
function image(img) {
|
|
if (!img) return null;
|
|
if (img.startsWith('http://') || img.startsWith('https://')) return img;
|
|
return s3Storage.getPublicUrl(`uploads/images/slider/${img}`);
|
|
}
|
|
|
|
const SliderSchema = mongoose.Schema({
|
|
title: String,
|
|
summaryTitle : String,
|
|
url : String,
|
|
newsTitle : String,
|
|
isLocal : {type : Boolean , default : false},
|
|
cover : {type: String, get: image , default : null},
|
|
index: {type : Number , default : null},
|
|
_creator: {type: mongoose.Schema.Types.ObjectId , ref: 'User'},
|
|
_updatedBy: {type: mongoose.Schema.Types.ObjectId , ref: 'User'},
|
|
siteMap : {type : Boolean , default : false},
|
|
modelType : String
|
|
});
|
|
|
|
SliderSchema.plugin(mongoosePaginate);
|
|
|
|
module.exports = mongoose.model('Slider', SliderSchema);
|