|
if (product_id) { |
|
queryToUse = `SELECT * FROM questions WHERE product_id = ${product_id} LIMIT ${(page || 1) * (count || 5) - (count || 5)}, ${(count || 5)}`; |
|
} else { |
|
queryToUse = `SELECT * FROM questions LIMIT ${(page || 1) * (count || 5) - (count || 5)}, ${(count || 5)}`; |
|
} |
It would be possible to simplify this code and reduce repetition by using a ternary operator inside the query statement instead of putting the query statement inside of a conditional:
`SELECT * FROM questions WHERE ${product_id ? `product_id = ${product_id} ` : ''}LIMIT...`
If we use this format, then we can get by with writing the query only once.
QuestionsAndAnswersAPI/server/models/model.js
Lines 9 to 13 in 9e8ff4f
It would be possible to simplify this code and reduce repetition by using a ternary operator inside the query statement instead of putting the query statement inside of a conditional:
If we use this format, then we can get by with writing the query only once.