-
Notifications
You must be signed in to change notification settings - Fork 44
Fatima databases week3 #40
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?
Fatima databases week3 #40
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
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.
missing check for integer
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're missing the actual Id of the product you're adding?
No description provided.