From 64cb6959cbba60a9078fdc5d5682cdc662da1081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Thu, 26 Nov 2020 20:32:07 +0100 Subject: [PATCH] BETTERZON-38: products findAll now returns the actual products from the DB --- Backend/src/products/products.service.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Backend/src/products/products.service.ts b/Backend/src/products/products.service.ts index f8281de..16ee44b 100644 --- a/Backend/src/products/products.service.ts +++ b/Backend/src/products/products.service.ts @@ -74,18 +74,23 @@ const products: Products = { export const findAll = async (): Promise => { let conn; + let prodRows = []; try { conn = await pool.getConnection(); - const rows = await conn.query("SELECT * FROM products"); - console.log(rows); //[ {val: 1}, meta: ... ] + const rows = await conn.query("SELECT product_id, name FROM products WHERE product_id = ?", 1); + for(let row in rows){ + if(row !== 'meta'){ + prodRows.push(rows[row]); + } + } } catch (err) { throw err; } finally { - if (conn) return conn.end(); + if (conn) conn.end(); } - return products; + return prodRows; }; export const find = async (id: number): Promise => {