Files
arakrail/api/models/blog/BlogPost.js
T
2020-11-23 19:39:26 +03:30

50 lines
1.1 KiB
JavaScript

const mongoose = require('mongoose')
function cover(img) {
return '/uploads/images/blog/' + img
}
const BlogPostSchema = mongoose.Schema({
cover: {type: String, get: cover},
published: {type: Boolean, default: true},
category: String,
post_details: {
fa: {
title: String,
description: String,
short_description: String
},
en: {
title: String,
description: String,
short_description: String
},
de: {
title: String,
description: String,
short_description: String
},
tr: {
title: String,
description: String,
short_description: String
},
it: {
title: String,
description: String,
short_description: String
}
},
created_at: String,
updated_at: String
}, {
toObject: {getters: true},
toJSON: {getters: true}
})
BlogPostSchema.virtual('thumb').get(function () {
return '/uploads/images/blog/thumb_' + this.cover.split('blog/')[1]
})
module.exports = mongoose.model('BlogPost', BlogPostSchema)