Skip to content

Conversation

@FatimaAbdimalik
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.

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()],
Copy link

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

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

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

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],
Copy link

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

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

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?

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