Skip to content

Add product creation functionality to the API #80

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

austenstone
Copy link
Member

This pull request introduces a new feature to allow the creation of products in the application. The most important changes include adding a new function to handle product creation in the model and updating the routes to handle the new product creation endpoint.

…om user-controlled sources

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@austenstone austenstone requested a review from Copilot April 2, 2025 19:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds product creation functionality to the API by introducing a new endpoint and a corresponding database insertion function. Key changes include:

  • Adding a new '/products/create' route to handle product creation requests.
  • Introducing a new create function in the products model to insert product records into the database.
  • Updating SQL queries to use parameterized arguments for secure database access.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
routes/products.js New endpoint for product creation without response handling.
model/products.js New create() function using a parameterized query, though it omits some product fields passed in by the route.

Tip: Leave feedback on Copilot's review comments with the 👎 and 👍 buttons to help improve review quality. Learn more


db_products.create(product)
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The product creation endpoint does not send a response back to the client after attempting to create the product. Consider adding proper response handling (e.g., res.send() or res.json()) to confirm the operation’s success or failure.

Suggested change
db_products.create(product)
db_products.create(product)
.then(function () {
res.json({ message: "Product created successfully" });
})
.catch(function (err) {
console.log(err);
res.status(500).json({ message: "Error creating product" });
});

Copilot uses AI. Check for mistakes.

Comment on lines +44 to +46
var q = "INSERT INTO products(name, description, price) VALUES($1, $2, $3);";

return db.one(q, [product.name, product.description, product.price]);
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQL query in the create() function only inserts the name, description, and price, while the route passes additional fields (image and username). Update the query to include the additional fields or adjust the route accordingly.

Suggested change
var q = "INSERT INTO products(name, description, price) VALUES($1, $2, $3);";
return db.one(q, [product.name, product.description, product.price]);
var q = "INSERT INTO products(name, description, price, image, username) VALUES($1, $2, $3, $4, $5);";
return db.one(q, [product.name, product.description, product.price, product.image, product.username]);

Copilot uses AI. Check for mistakes.

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.

1 participant