26 lines
889 B
JavaScript
26 lines
889 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/occasion/${img}`);
|
|
}
|
|
|
|
const OccasionSchema = mongoose.Schema({
|
|
title : String,
|
|
mainCover: {type: String, get: image, default: null},
|
|
startDate : Date,
|
|
endDate : Date,
|
|
index: {type: Number, default: null},
|
|
publish : {type : Boolean , default: true},
|
|
status : {type : Boolean , default: false},
|
|
_creator :{type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
|
_updatedBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
|
});
|
|
|
|
OccasionSchema.plugin(mongoosePaginate);
|
|
|
|
module.exports = mongoose.model('Occasion', OccasionSchema);
|