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

101 lines
1.9 KiB
JavaScript

const mongoose = require('mongoose')
function productImage(img) {
return '/uploads/images/products/' + img
}
function ProductImageGallery(img) {
return '/uploads/images/products/gallery/' + img
}
const ProductFeatureSchema = mongoose.Schema({
fa: {
name: String,
value: String
},
en: {
name: String,
value: String
},
de: {
name: String,
value: String
},
tr: {
name: String,
value: String
},
it: {
name: String,
value: String
},
created_at: String
})
const ProductImageSchema = mongoose.Schema({
image: {type: String, get: ProductImageGallery},
created_at: String
}, {
toObject: {getters: true},
toJSON: {getters: true}
})
const ProductSchema = mongoose.Schema({
image: {type: String, get: productImage},
stock: Number,
category: String,
product_details: {
fa: {
name: String,
description: String,
price: {
type: Number,
default: 0
}
},
en: {
name: String,
description: String,
price: {
type: Number,
default: 0
}
},
de: {
name: String,
description: String,
price: {
type: Number,
default: 0
}
},
it: {
name: String,
description: String,
price: {
type: Number,
default: 0
}
},
tr: {
name: String,
description: String,
price: {
type: Number,
default: 0
}
}
},
product_features: [ProductFeatureSchema],
product_images: [ProductImageSchema],
created_at: String,
updated_at: String
}, {
toObject: {getters: true},
toJSON: {getters: true}
})
module.exports = mongoose.model('Product', ProductSchema)