-
Notifications
You must be signed in to change notification settings - Fork 44
Orhan week 3 #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Orhan week 3 #39
Conversation
Ashaghel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work
| const attributes = [searchName] | ||
| const sql1 = "select p.product_name, pa.unit_price, s.supplier_name from product_availability pa join products p on pa.prod_id = p.id join suppliers s on pa.supp_id = s.id where Lower(p.product_name) like '%'|| $1 ||'%'"; | ||
| const sql2 = 'select p.product_name, pa.unit_price, s.supplier_name from product_availability pa join products p on pa.prod_id = p.id join suppliers s on pa.supp_id = s.id'; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while this will work with no issue
it can be harder to maintain and scale up
for better fix you can have arguments and where conditions alone as variables that are added to main string on a conditions
| const prod_id = req.body.prod_id; | ||
| const supp_id = req.body.supp_id; | ||
| const price = req.body.unit_price; | ||
| if (price < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
casting price from string to number
also a check for integers ?
| const sql_supp = "select * from product_availability where supp_id = $1" | ||
| db.query(sql_supp, [supp_id], (err, result) => { | ||
| if (err || result.rows.length == 0) { | ||
| res.status(500).send(err, "Didnt match foreign key supp_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a much friendlier message is usually sent to the user, you never send db secrets
No description provided.