diff --git a/backend/src/routes/products.js b/backend/src/routes/products.js index ce7d9dc..1019cad 100644 --- a/backend/src/routes/products.js +++ b/backend/src/routes/products.js @@ -34,20 +34,20 @@ router.get('/', async (req, res, next) => { const { category, type, search } = req.query; let whereConditions = []; - let queryParams = [req.user.id]; - let paramCount = 1; + let sharedProductsParams = []; + let paramCount = 0; - // Build WHERE clause for filtering + // Build WHERE clause for filtering shared products if (category) { paramCount++; whereConditions.push(`pc.id = $${paramCount}`); - queryParams.push(category); + sharedProductsParams.push(category); } if (type) { paramCount++; whereConditions.push(`p.product_type = $${paramCount}`); - queryParams.push(type); + sharedProductsParams.push(type); } if (search) { @@ -58,7 +58,7 @@ router.get('/', async (req, res, next) => { paramCount++; const searchParam3 = paramCount; whereConditions.push(`(p.name ILIKE $${searchParam1} OR p.brand ILIKE $${searchParam2} OR p.active_ingredients ILIKE $${searchParam3})`); - queryParams.push(`%${search}%`, `%${search}%`, `%${search}%`); + sharedProductsParams.push(`%${search}%`, `%${search}%`, `%${search}%`); } const whereClause = whereConditions.length > 0 ? `AND ${whereConditions.join(' AND ')}` : ''; @@ -83,7 +83,7 @@ router.get('/', async (req, res, next) => { ORDER BY p.name `; - const sharedResult = await pool.query(sharedProductsQuery, queryParams.slice(1)); + const sharedResult = await pool.query(sharedProductsQuery, sharedProductsParams); // Get user's custom products const userProductsQuery = `