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

86 lines
2.2 KiB
JavaScript

const mongoose = require('mongoose')
function productImage(img) {
return '/uploads/images/products/' + img
}
function productPDF(file) {
return '/uploads/pdf/' + file
}
const ProductImageSchema = mongoose.Schema({
image: {type: String, get: productImage},
created_at: String
}, {
toObject: {getters: true},
toJSON: {getters: true}
})
const ProductPDFSchema = mongoose.Schema({
file: {type: String, get: productPDF},
pdf_details: {
fa: {
name: String
},
en: {
name: String
}
},
created_at: String
}, {
toObject: {getters: true},
toJSON: {getters: true}
})
const ProductSchema = mongoose.Schema({
cover: {type: String, get: productImage},
images: [ProductImageSchema],
more_section_image1: {type: String, get: productImage},
more_section_image2: {type: String, get: productImage},
render_image1: {type: String, get: productImage},
render_image2: {type: String, get: productImage},
chart_image: {type: String, get: productImage},
pdf_files: [ProductPDFSchema],
category: String,
more_section: {type: Boolean, default: true},
download_section: {type: Boolean, default: true},
product_details: {
fa: {
name: String,
short_description: String,
page_title: String,
page_description: String,
more_title1: String,
more_description1: String,
more_title2: String,
more_description2: String,
render_caption1: String,
render_caption2: String,
chart_title: String,
chart_description: String
},
en: {
name: String,
short_description: String,
page_title: String,
page_description: String,
more_title1: String,
more_description1: String,
more_title2: String,
more_description2: String,
render_caption1: String,
render_caption2: String,
chart_title: String,
chart_description: String
}
},
created_at: String,
updated_at: String
}, {
toObject: {getters: true},
toJSON: {getters: true}
})
module.exports = mongoose.model('Product', ProductSchema)