From 4dde3eb764c8b46c636aae145e1a5d8da03636af Mon Sep 17 00:00:00 2001 From: ImegaCrack <72518019+OmegaCrack@users.noreply.github.com> Date: Sat, 28 Nov 2020 21:04:03 +0300 Subject: [PATCH] Update productController.js Using name to find and update products. --- controllers/productController.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/controllers/productController.js b/controllers/productController.js index d304e4c..8c1dbe3 100644 --- a/controllers/productController.js +++ b/controllers/productController.js @@ -17,9 +17,10 @@ async function getProducts(req, res) { // @desc Gets Single Product // @route GET /api/product/:id -async function getProduct(req, res, id) { +async function getProduct(req, res, name) { try { - const product = await Product.findById(id) + const product = await Product.findByName(name) + if(!product) { res.writeHead(404, { 'Content-Type': 'application/json' }) @@ -59,9 +60,9 @@ async function createProduct(req, res) { // @desc Update a Product // @route PUT /api/products/:id -async function updateProduct(req, res, id) { +async function updateProduct(req, res, name) { try { - const product = await Product.findById(id) + const product = await Product.findByName(name) if(!product) { res.writeHead(404, { 'Content-Type': 'application/json' }) @@ -114,4 +115,4 @@ module.exports = { createProduct, updateProduct, deleteProduct -} \ No newline at end of file +}