async function createOrder(user){
    const trackingNum = uuidv4();
    let cart = await Cart.findOne({uid:user.cartId}).then((cart) => cart).catch((err) => null);
    
    if (cart==null){
        return null;
    }
    
    let productItems = [];
    for (var i = 0; i < cart.items.length; i++){
        let pId = cart.items[i].pid;
        let product = await getProductByID(pId);
        productItems.push({
            title:product.title,
            price:product.price,
            image_link:product.image_link,
            pattern:product.pattern,
            quantity:cart.items[i].quantity
        });
    }
    
    var newOrder = new Order({
        customer: user,
        trackingNumber: trackingNum,
        products: productItems
    })
    
    let setOrder = await newOrder.save().then((doc) => doc).catch((err) => {console.log(err); null});
    
    return setOrder;
}
// Pass in user and cart object
Pass in user and cart object
Pass in user and cart object
async function createOrder(user){
    const trackingNum = uuidv4();
    let cart = await Cart.findOne({uid:user.cartId}).then((cart) => cart).catch((err) => null);
    if (cart==null){
        return null;
    }
    let productItems = [];
    for (var i = 0; i < cart.items.length; i++){
        let pId = cart.items[i].pid;
        let product = await getProductByID(pId);
        productItems.push({
            title:product.title,
            price:product.price,
            image_link:product.image_link,
            pattern:product.pattern,
            quantity:cart.items[i].quantity
        });
    }
    var newOrder = new Order({
        customer: user,
        trackingNumber: trackingNum,
        products: productItems
    })
    let setOrder = await newOrder.save().then((doc) => doc).catch((err) => {console.log(err); null});
    return setOrder;
}
async function createOrder ( user ) { const trackingNum = uuidv4 ( ) ; let cart = await Cart . findOne ( { uid : user . cartId } ) . then ( ( cart ) => cart ) . catch ( ( err ) => null ) ; if ( cart == null ) { return null ; } let productItems = [ ] ; for ( var i = 0 ; i < cart . items . length ; i ++ ) { let pId = cart . items [ i ] . pid ; let product = await getProductByID ( pId ) ; productItems . push ( { title : product . title , price : product . price , image_link : product . image_link , pattern : product . pattern , quantity : cart . items [ i ] . quantity } ) ; } var newOrder = new Order ( { customer : user , trackingNumber : trackingNum , products : productItems } ) let setOrder = await newOrder . save ( ) . then ( ( doc ) => doc ) . catch ( ( err ) => { console . log ( err ) ; null } ) ; return setOrder ; }
Pass in user and cart object
Pass in user and cart object