From 71735255b87d0372f6a015356fe512e470cec533 Mon Sep 17 00:00:00 2001 From: dhdemerson Date: Fri, 27 Jun 2014 10:30:09 -0700 Subject: [PATCH] Implement put delete for products --- routes/api-data.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/routes/api-data.js b/routes/api-data.js index 03658a2..92f1204 100644 --- a/routes/api-data.js +++ b/routes/api-data.js @@ -151,6 +151,41 @@ exports.postProduct = function (req, res) { }); }; +exports.putProduct = function(req, res) { + if (!req.session.email) { + return error(res, 'Not logged in.'); + } + Product.findById(req.params.product_id, function(err, product) { + if (err) { + return error(res, err, console); + } + + product.name = req.body.name; + + product.save(function (err) { + if (err) { + return error(res, err, console); + } + res.json(product); + }); + }); +}; + +exports.deleteProduct = function(req, res) { + if (!req.session.email) { + return error(res, 'Not logged in.'); + } + Product.findById(req.params.product_id, function(err, product) { + if (err) { + return error(res, err, console); + } + + product.remove(); + + res.json(product); + }); +}; + // Projects. exports.getProjects = function (req, res) {