asdflkj
This commit is contained in:
@@ -34,20 +34,20 @@ router.get('/', async (req, res, next) => {
|
|||||||
const { category, type, search } = req.query;
|
const { category, type, search } = req.query;
|
||||||
|
|
||||||
let whereConditions = [];
|
let whereConditions = [];
|
||||||
let queryParams = [req.user.id];
|
let sharedProductsParams = [];
|
||||||
let paramCount = 1;
|
let paramCount = 0;
|
||||||
|
|
||||||
// Build WHERE clause for filtering
|
// Build WHERE clause for filtering shared products
|
||||||
if (category) {
|
if (category) {
|
||||||
paramCount++;
|
paramCount++;
|
||||||
whereConditions.push(`pc.id = $${paramCount}`);
|
whereConditions.push(`pc.id = $${paramCount}`);
|
||||||
queryParams.push(category);
|
sharedProductsParams.push(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
paramCount++;
|
paramCount++;
|
||||||
whereConditions.push(`p.product_type = $${paramCount}`);
|
whereConditions.push(`p.product_type = $${paramCount}`);
|
||||||
queryParams.push(type);
|
sharedProductsParams.push(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
@@ -58,7 +58,7 @@ router.get('/', async (req, res, next) => {
|
|||||||
paramCount++;
|
paramCount++;
|
||||||
const searchParam3 = paramCount;
|
const searchParam3 = paramCount;
|
||||||
whereConditions.push(`(p.name ILIKE $${searchParam1} OR p.brand ILIKE $${searchParam2} OR p.active_ingredients ILIKE $${searchParam3})`);
|
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 ')}` : '';
|
const whereClause = whereConditions.length > 0 ? `AND ${whereConditions.join(' AND ')}` : '';
|
||||||
@@ -83,7 +83,7 @@ router.get('/', async (req, res, next) => {
|
|||||||
ORDER BY p.name
|
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
|
// Get user's custom products
|
||||||
const userProductsQuery = `
|
const userProductsQuery = `
|
||||||
|
|||||||
Reference in New Issue
Block a user