Fatima databases week3#40
Conversation
Ashaghel
left a comment
There was a problem hiding this comment.
Good work Fatima
After finishing a piece of code. Try to take a break and come back and read as a stranger reviewing it
Duck coding can help as well
| let name = req.query.name; | ||
| db.query( | ||
| "SELECT p.product_name, pa.unit_price, s.supplier_name FROM products p JOIN product_availability pa ON (p.id = pa.prod_id) JOIN suppliers s ON (s.id = pa.supp_id ) WHERE lower(p.product_name) LIKE '%' || $1 || '%'", | ||
| [name.toLowerCase()], |
There was a problem hiding this comment.
nicely done,setting both to lower case help widen your search
| app.post("/availability", (req, res) => { | ||
| let productSupplier = Number(req.body.supp_id); | ||
| let productPrice = Number(req.body.unit_price); | ||
| if (productPrice > 0) { |
| if (productPrice > 0) { | ||
| const query = | ||
| "INSERT INTO product_availability (supp_id, unit_price) " + | ||
| "VALUES ($1,$2) RSTURNING id AND supp_id and id IS NOT NULL"; |
There was a problem hiding this comment.
there are couple of typos here , Returning not rsturning
usually you dont put conditions on returning
| "UPDATE customers SET name=$2, address=$3, city=$4, country=$5 WHERE id $1", | ||
| [custId, changedName, changedAddress, changedCity, changedCountry], | ||
| (error) => { | ||
| // if (!error) { |
There was a problem hiding this comment.
There are some issues here
why the error handling is commented also what if user forgot to send city, this will set it to null. Some validation needed
| let orderId = Number(req.params.orderId); | ||
| db.query( | ||
| "DELETE FROM order_items WHERE order_id = $1", | ||
| [orderId], |
There was a problem hiding this comment.
you're missing deleting from order table, the actually Id
| app.delete("customers/:customerId", (req, res) => { | ||
| let customerId = Number(req.params.customerId); | ||
| db.query( | ||
| "DELETE o.* FROM orders o JOIN customers c ON (o.customer_id = c.id WHERE c.id = £1", |
There was a problem hiding this comment.
on and where should not be put on same ()
|
|
||
| // create a new product availability | ||
| app.post("/availability", (req, res) => { | ||
| let productSupplier = Number(req.body.supp_id); |
There was a problem hiding this comment.
you're missing the actual Id of the product you're adding?
No description provided.