-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
QuestionsAndAnswersAPI/server/models/model.js
Lines 9 to 13 in 9e8ff4f
| 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels