/**
 * Created by manthanhd on 12/5/2015.
 */
function OrderRoute(express, OrderModel) {
    var router = express.Router();

    router.get('/merchant/:merchantId', function (req, res) {
        var merchantId = req.params.merchantId;
        if (!merchantId) {
            return res.status(400).send();
        }
        OrderModel.find({merchantId: merchantId}, function (err, orders) {
            if (err) {
                console.log(err);
                return res.status(500).send();
            }

            if (!orders || orders.length == 0) {
                return res.status(404).send();
            }

            return res.send(orders);
        });
    });

    router.get('/product/:productId', function (req, res) {
        var productId = req.params.productId;
        if (!productId) {
            return res.status(400).send();
        }

        OrderModel.find({productId: productId}, function (err, orders) {
            if (err) {
                console.log(err);
                return res.status(500).send();
            }

            if (!orders || orders.length == 0) {
                return res.status(404).send();
            }

            return res.send(orders);
        });
    });

    router.post('/:merchantId/:productId/create', function (req, res) {
        if (!req.params.merchantId || !req.params.productId || !req.body.inventoryId || !req.body.status || !req.body.quantity || !req.body.price || !req.body.amount || !req.body.description) {
            return res.status(400).send();
        }
        var neworder = new OrderModel();
        neworder.inventoryId = req.body.inventoryId;
        neworder.merchantId = req.params.merchantId;
        neworder.productId = req.params.productId;
        neworder.status = req.body.status;
        neworder.quantity = req.body.quantity;
        neworder.description = req.body.description;
        neworder.save(function (err, savedOrder) {
            if (err) {
                console.log(err);
                return res.status(500).send();
            }

            if (savedOrder) {
                return res.send(savedOrder);
            }

            return res.status(500).send();
        });
    });

    return router;
}

module.exports = OrderRoute;

@@ -2198,24 +2198,921 @@
 );%0A    %7D);%0A%0A
+    router.put(%22/:orderId/:status%22, function(req, res) %7B%0A        var orderId = req.params.orderId;%0A        var status = req.params.status;%0A        if(!orderId %7C%7C !status) %7B%0A            return res.status(400).send();%0A        %7D%0A%0A        OrderModel.findOne(%7B_id: orderId%7D, function(err, order) %7B%0A            if(err) %7B%0A                console.log(err);%0A                return res.status(500).send();%0A            %7D%0A%0A            if(!order) %7B%0A                return res.status(404).send();%0A            %7D%0A%0A            order.status = status;%0A            order.save(function(err, savedOrder) %7B%0A                if(err) %7B%0A                    console.log(err);%0A                    return res.status(500).send();%0A                %7D%0A%0A                if(!savedOrder) %7B%0A                    return res.status(404).send();%0A                %7D%0A%0A                return res.send(order);%0A            %7D)%0A        %7D)%0A    %7D);%0A%0A
     return r

Order status update endpoint added.