mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2024-11-22 14:23:57 +00:00
BETTERZON-38: products findAll now returns the actual products from the DB
This commit is contained in:
parent
82b3521f9e
commit
64cb6959cb
|
@ -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> => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user