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> => { export const findAll = async (): Promise<Products> => {
let conn; let conn;
let prodRows = [];
try { try {
conn = await pool.getConnection(); conn = await pool.getConnection();
const rows = await conn.query("SELECT * FROM products"); const rows = await conn.query("SELECT product_id, name FROM products WHERE product_id = ?", 1);
console.log(rows); //[ {val: 1}, meta: ... ] for(let row in rows){
if(row !== 'meta'){
prodRows.push(rows[row]);
}
}
} catch (err) { } catch (err) {
throw err; throw err;
} finally { } finally {
if (conn) return conn.end(); if (conn) conn.end();
} }
return products; return prodRows;
}; };
export const find = async (id: number): Promise<Product> => { export const find = async (id: number): Promise<Product> => {