From e06804cc9231dd76bdcc3c9e13e44d8e9db33392 Mon Sep 17 00:00:00 2001 From: 65160383 <65160383@go.buu.ac.th> Date: Mon, 24 Mar 2025 17:00:01 +0700 Subject: [PATCH] werehouse_db --- controllers/productController.js | 62 -------------------------------- package.json | 1 + 2 files changed, 1 insertion(+), 62 deletions(-) diff --git a/controllers/productController.js b/controllers/productController.js index b72aeef..1ed0730 100644 --- a/controllers/productController.js +++ b/controllers/productController.js @@ -127,68 +127,6 @@ exports.searchProducts = (req, res) => { }); }; -// ฟังก์ชันสำหรับการสั่งสินค้า -exports.placeOrder = (req, res) => { - const { product_id, quantity } = req.body; - - // ตรวจสอบสินค้าในคลัง - const query = 'SELECT * FROM products WHERE id = ?'; - db.query(query, [product_id], (err, result) => { - if (err) { - console.error(err); - return res.send(` - <script> - alert('เกิดข้อผิดพลาดในการสั่งซื้อ'); - window.location.href = '/products'; - </script> - `); - } - - if (result.length > 0) { - const product = result[0]; - - // ตรวจสอบว่าสินค้ามีจำนวนเพียงพอหรือไม่ - if (product.quantity < quantity) { - return res.send(` - <script> - alert('สินค้าในคลังไม่เพียงพอ'); - window.location.href = '/products'; - </script> - `); - } - - // อัพเดทจำนวนสินค้า - const updateQuery = 'UPDATE products SET quantity = quantity - ? WHERE id = ?'; - db.query(updateQuery, [quantity, product_id], (err, updateResult) => { - if (err) { - console.error(err); - return res.send(` - <script> - alert('เกิดข้อผิดพลาดในการอัพเดทจำนวนสินค้า'); - window.location.href = '/products'; - </script> - `); - } - - // แสดงข้อความสำเร็จและรีเฟรชหน้า - res.send(` - <script> - alert('สั่งซื้อสำเร็จ'); - window.location.href = '/products'; - </script> - `); - }); - } else { - return res.send(` - <script> - alert('ไม่พบสินค้า'); - window.location.href = '/products'; - </script> - `); - } - }); -}; - // แสดงหน้าเพิ่มสินค้า exports.addProductPage = (req, res) => { const query = 'SELECT * FROM categories ORDER BY name'; diff --git a/package.json b/package.json index 320be2c..eef8ab1 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "", "main": "app.js", + "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, -- GitLab