BETTERZON-38: products findAll now returns the actual products from the DB

This commit is contained in:
Patrick Müller 2020-11-26 20:32:07 +01:00
parent 82b3521f9e
commit 64cb6959cb

View File

@ -74,18 +74,23 @@ const products: Products = {
export const findAll = async (): Promise<Products> => {
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<Product> => {