Métodos
/**
* Using Rails-like standard naming convention for endpoints.
* GET /api/products -> index
* GET /api/products/:id -> show
* POSG /api/products -> create
*/
const Product = require('./product.model');
// Gets a list of products
function index(req, res) {
return Product.find().exec()
.then(respondWithResult(res))
.catch(handleError(res));
}
// Create product
function create(req, res) {
return Product.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
// Gets a single product from the DB
function show(req, res) {
return Product.findById(req.params.id).exec()
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
module.exports = {
create,
show,
index,
};
Repositorio: Add the Product's controller
Last updated
Was this helpful?