Skip to content

Commit

Permalink
Implement put delete for products
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdemerson committed Jun 27, 2014
1 parent b6d5767 commit 7173525
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions routes/api-data.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 7173525

Please sign in to comment.