Files
arakrail/api/models/blog/BlogPost.js
T
Amir Mohamadi bc5e617778 back-end done
2020-12-10 16:36:48 +03:30

35 lines
789 B
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
}
},
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)