const request = require('request-promise');
const orderServiceUrl = process.env.ORDER_SERVICE_URL || "https://order-api.shopperr.in";

const onOrderCreated = async (orders)=>{
    return await Promise.allSettled(orders.map(async (order)=>{
        return await request.post(orderServiceUrl+"/order/createPo?order_id="+order._id.toString()).then((respo) => {
            return { 'error': 0, 'message': 'Products Updated.',data:respo };
        }).catch((error)=>{
            return { 'error': 1, 'message': error.toString() };
        });
    }))
 
}

   
module.exports = {onOrderCreated}
