let mongoose = require('mongoose'),
Schema = mongoose.Schema;
let idvalidator = require('mongoose-id-validator');
let SizeSchema = require('./Size');
let ProductExtraSchema = require('./ProductExtra');
let CartItemSchema = new Schema({
product_id: {
type: Schema.Types.ObjectId,
ref: 'Product',
required: true
},
sku: {
type: String,
required: true,
trim: true,
lowercase: true
},
name: {
type: String,
required: true,
trim: true
},
description: {
type: String,
trim: true,
alias: "desc"
},
price: {
type: Number,
min: 0,
required: true,
default: 0
},
priceWithoutTax:{
type: Number,
min: 0,
required: true,
default: 0
},
total: {
type: Number,
min: 0,
required: true,
default: 0
},
totalWithoutTax:{
type: Number,
min: 0,
required: true,
default: 0
},
taxable: {
type: Boolean,
required: true,
default: false
},
taxRate: {
type: Number,
required: true,
min: 0,
default: 0.2
},
quantity: {
type: Number,
min: 1,
required: true,
default: 1
},
size: SizeSchema,
extras: [ProductExtraSchema]
},
{
timestamps: true,
id: false
}
);
CartItemSchema.set('toObject', {virtuals: true});
CartItemSchema.set('toJSON', {virtuals: true});
CartItemSchema.plugin(idvalidator);
module.exports = CartItemSchema;