mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2024-11-22 06:13:57 +00:00
BETTERZON-70: Adding API endpoint to get details for a list of products (#30)
This commit is contained in:
parent
57962a7973
commit
432b63b6e4
|
@ -69,6 +69,25 @@ productsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// GET products/list/[1,2,3]
|
||||||
|
|
||||||
|
productsRouter.get('/list/:ids', async (req: Request, res: Response) => {
|
||||||
|
const ids: [number] = JSON.parse(req.params.ids);
|
||||||
|
|
||||||
|
if (!ids) {
|
||||||
|
res.status(400).send('Missing parameters.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const products: Products = await ProductService.findList(ids);
|
||||||
|
|
||||||
|
res.status(200).send(products);
|
||||||
|
} catch (e) {
|
||||||
|
res.status(404).send(e.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// GET products/bestDeals
|
// GET products/bestDeals
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,29 @@ export const findBySearchTerm = async (term: string): Promise<Products> => {
|
||||||
return prodRows;
|
return prodRows;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const findList = async (ids: [number]): Promise<Products> => {
|
||||||
|
let conn;
|
||||||
|
let prodRows = [];
|
||||||
|
try {
|
||||||
|
conn = await pool.getConnection();
|
||||||
|
const rows = await conn.query('SELECT product_id, name, asin, is_active, short_description, long_description, image_guid, date_added, last_modified, manufacturer_id, selling_rank, category_id FROM products WHERE product_id IN (?)', [ids]);
|
||||||
|
for (let row in rows) {
|
||||||
|
if (row !== 'meta') {
|
||||||
|
prodRows.push(rows[row]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
} finally {
|
||||||
|
if (conn) {
|
||||||
|
conn.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prodRows;
|
||||||
|
};
|
||||||
|
|
||||||
// export const create = async (newItem: Product): Promise<void> => {
|
// export const create = async (newItem: Product): Promise<void> => {
|
||||||
// let conn;
|
// let conn;
|
||||||
// try {
|
// try {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user