Skip to content

Conversation

@OBakir90
Copy link

No description provided.

Copy link

@Ashaghel Ashaghel left a 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';

Copy link

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) {
Copy link

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")
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants