Skip to content
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

chore: Add create product functionality to products route #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion model/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,23 @@

}

function create(product) {

Check failure on line 52 in model/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

model/products.js#L52

`meta.messages` must contain at least one violation message.

Check warning on line 52 in model/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

model/products.js#L52

`meta.schema` is required (use [] if rule has no schema).

Check failure on line 52 in model/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

model/products.js#L52

`meta.type` is required (must be either `problem`, `suggestion`, or `layout`).
var q = "INSERT INTO products(name, description, price) VALUES('" +
product.name + "', '" +
product.description + "', '" +
product.price +
"');";

return db.one(q);

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query string depends on a
user-provided value
.
This query string depends on a
user-provided value
.
}

var actions = {
"list": list_products,
"getProduct": getProduct,
"search": search,
"purchase": purchase,
"getPurchased": get_purcharsed
"getPurchased": get_purcharsed,
"create": create
}

module.exports = actions;
18 changes: 18 additions & 0 deletions routes/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@

});

router.all('/products/create', function(req, res, next) {

Check failure on line 147 in routes/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

routes/products.js#L147

'res' is defined but never used.

Check failure on line 147 in routes/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

routes/products.js#L147

'res' is defined but never used.
let params = null;
if (req.method == "GET"){
params = url.parse(req.url, true).query;
} else {
params = req.body;
}

let product = null;
product = {
name: params.name,
description: params.description,
price: params.price,
image: params.image,
username: req.session.user_name
}

db_products.create(product)
});

module.exports = router;