router.post('/', async (req, res) => {
    const orderItemsIds = Promise.all(req.body.orderItems.map(async orderitem =>{
        let newOrderItem = new OrderItem({
            quantity:orderitem.quantity,
            product: orderitem.product.id
        })

        newOrderItem =await newOrderItem.save();

        return newOrderItem._id;
    }))

    const orderItemIdsResolved = await orderItemsIds;
    console.log(orderItemIdsResolved);

    let order = new Order({
        orderItems: orderItemIdsResolved,
        shippingAddress1: req.body.shippingAddress1,
        shippingAddress2: req.body.shippingAddress2,
        city: req.body.city,
        zip: req.body.zip,
        country: req.body.country,
        phone: req.body.phone,
        status: req.body.status,
        totalPrice: req.body.totalPrice,
        user: req.body.user,
    })
    order = await order.save();

    if (!order) return res.status(404).send('The order is not created successfully')

    res.send(order)
})

I want to the orderitem which is a array of product and the quantity therefore i used .map but it showing .map is undefined. I tried a adding a empty array but it didn't worked

0

There are 0 best solutions below