{"size": 1686, "ext": "js", "max_stars_repo_path": "models/orderlistmodel.js", "max_stars_repo_name": "rajachinth/ecommerce_serverside_dev", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/orderlistmodel.js", "max_issues_repo_name": "rajachinth/ecommerce_serverside_dev", "max_issues_repo_issues_event_min_datetime": "2020-11-02T19:56:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T11:57:47.000Z", "max_forks_repo_path": "models/orderlistmodel.js", "max_forks_repo_name": "rajachinth/ecommerce_serverside_dev", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 34.4081632653, "max_line_length": 69, "alphanum_fraction": 0.6411625148}
const Joi=require('@hapi/joi');
const mongoose=require('mongoose');

const orderListSchema=new mongoose.Schema({
        userID:mongoose.Schema.Types.ObjectId,
        orderID:{type:String,required:true},
        orderDate:{type:Date},
        productDetails:[{
            productID:{type:String,required:true,max:6},
            title:{type:String,required:true},
            price:{type:Number,required:true},
            itemCount:{type:Number,required:false},
            imageURL:{type:String,require:false}
        }],
        productSummary:{
            totalItemCount:{type:Number,require:true},
            totalItemCost:{type:Number,require:true}
        },
        shippingDetails:mongoose.Schema.Types.ObjectId
});
const orderListModel=mongoose.model('orderListData',orderListSchema);

function orderListModelValidation(orderListData)
{
    const orderListSchema=Joi.object({
            productDetails:Joi.array().items(
                {   productID:Joi.string().required().max(6),
                    title:Joi.string().required(),
                    price:Joi.number().required(),
                    itemCount:Joi.number(),
                    imageURL:Joi.string(),
                })
    });
    let validate=orderListSchema.validate(orderListData);
    return validate;
}
function idValidation(data)
{
    const idValidationSchema=Joi.object({
        userID:Joi.any().required(),
        orderID:Joi.string().required(),    
    });
    let validate=idValidationSchema.validate(data);
    return validate;
}

module.exports.orderListModel=orderListModel;
module.exports.orderListModelValidation=orderListModelValidation;
module.exports.idValidation=idValidation;