Skip to content

Commit f209d86

Browse files
authored
add input validation to express sample (#33)
1 parent 80a8a10 commit f209d86

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ams-express-shopping/service/orders.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ const createOrder = (req, res) => {
5353
*/
5454

5555
const { productId, quantity } = req.body;
56+
if (!Number.isInteger(productId) || productId < 0 ||
57+
!Number.isInteger(quantity) || quantity <= 0) {
58+
return res.status(400).json({ message: 'Invalid productId or quantity' });
59+
}
60+
5661
const product = db.products.find(p => p.id === productId);
5762
if (!product) {
5863
return res.status(404).json({ message: 'Product not found' });

0 commit comments

Comments
 (0)