From d5b001b31fd30afe1ac32bde81c2ee6f0f78d780 Mon Sep 17 00:00:00 2001 From: Chathurya99 <119391066+Chathurya99@users.noreply.github.com> Date: Fri, 20 Jan 2023 09:40:11 +0530 Subject: [PATCH 1/3] Update server.js --- server.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 9e2f78d..c9efccf 100644 --- a/server.js +++ b/server.js @@ -242,11 +242,12 @@ app.post("/api/suppliers/", (req, res, next) => { const { supplierName, address, joinedDate, - mobileNo + mobileNo, + live } = req.body; - var sql = 'INSERT INTO suppliers (supplierName, address, joinedDate, mobileNo) VALUES (?,?,?,?)' - var params = [supplierName, address, joinedDate, mobileNo] + var sql = 'INSERT INTO suppliers (supplierName, address, joinedDate, mobileNo, live) VALUES (?,?,?,?,?)' + var params = [supplierName, address, joinedDate, mobileNo, live] db.run(sql, params, function (err, result) { if (err) { @@ -283,8 +284,58 @@ app.delete("/api/suppliers/deleteAll/:id", (req, res, next) => { } }); +app.post("/api/customers/", (req, res, next) => { + + try { + var errors = [] + + if (!req.body) { + errors.push("An invalid input"); + } + + const { + name, + address, + email, + dateOfBirth, + gender, + age, + cardHolderName, + cardNumber, + expiryDate, + cvv, + timeStamp, + } = req.body; + + var sql = 'INSERT INTO customers (name, address, email, dateOfBirth, gender, age, cardHolderName,cardNumber, expiryDate, cvv, timeStamp ) VALUES (?,?,?,?,?,?,?,?,?,?,?)' + var params = [name, address, email, dateOfBirth, gender, age, cardHolderName, cardNumber, expiryDate, cvv, timeStamp] + db.run(sql, params, function (err, result) { + + if (err) { + res.status(400).json({ "error": err.message }) + return; + } else { + res.json({ + "message": "success", + "data": req.body, + "id": this.lastID + }) + } + + }); + } catch (E) { + + res.status(400).send(E); + } +}); + + // Root path app.get("/", (req, res, next) => { res.json({ "message": "University of Moratuwa" }) -}); \ No newline at end of file +}); + + + + From d1082225ba81c9cbdcb3e37c2f9fa2d4cbd0c8be Mon Sep 17 00:00:00 2001 From: Chathurya99 <119391066+Chathurya99@users.noreply.github.com> Date: Fri, 20 Jan 2023 09:45:14 +0530 Subject: [PATCH 2/3] Update database.js --- database.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/database.js b/database.js index 43e3342..9dda583 100644 --- a/database.js +++ b/database.js @@ -29,7 +29,7 @@ let db = new sqlite3.Database(DBSOURCE, (err) => { } else { // Table just created, creating some rows var insert = 'INSERT INTO products (productName, description, category, brand, expiredDate, manufacturedDate, batchNumber, unitPrice, quantity, createdDate) VALUES (?,?,?,?,?,?,?,?,?,?)' - db.run(insert, ["White Basmathi Rice", "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.", "Rice", "CIC", "2023.05.04", "2022.02.20", 324567, , 1020, 200, "2022.02.24"]) + db.run(insert, ["White Basmathi Rice", "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.", "Rice", "CIC", "2023.05.04", "2022.02.20", 324567, 1020, 200, "2022.02.24"]) } }) @@ -39,22 +39,52 @@ let db = new sqlite3.Database(DBSOURCE, (err) => { supplierName text, address text, joinedDate text, - mobileNo text + mobileNo text, + live text )`, (err) => { if (err) { // Table already created } else { // Table just created, creating some rows - var insert = 'INSERT INTO suppliers (supplierName, address, joinedDate, mobileNo) VALUES (?,?,?,?)' - db.run(insert, ["D.J.Ishara", "345A ,R.A De Mel Road, Colombo 3", "16/3/2022", "0776600933"]) + var insert = 'INSERT INTO suppliers (supplierName, address, joinedDate, mobileNo, live) VALUES (?,?,?,?,?)' + db.run(insert, ["D.J.Ishara", "345A ,R.A De Mel Road, Colombo 3", "16/3/2022", "0776600933", "tv"]) + } + + }) + + + + db.run(`CREATE TABLE customers ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name text, + address text, + emai text, + dateofbirth text, + gender text, + age text, + cardHolderName text, + expirydate text, + cvv text, + timeStamp text + )`, (err) => { + if (err) { + // Table already created + } else { + // Table just created, creating some rows + var insert = 'INSERT INTO customers (name, address, emai, dateOfBirth, gender, age, cardHolderName, cardNumber, expiryDate, cvv, timeStamp ) VALUES (?,?,?,?,?,?,?,?,?,?,?)' + db.run(insert, ["A.D.Lakith Dharmasiri", "No 324/A Ra De Mel Road,Colombo", "lakith@gmail.com", "1991.02.25", "female", "28", "A.D.L.Dharmasiri", "102445217895", "12/2022", "245", "2022-12-31 23:59:59"]) } }) + } }) module.exports = db + + + From 0a8eaa47c6882542c0e79f8d9bf91e24af280723 Mon Sep 17 00:00:00 2001 From: Chathurya99 <119391066+Chathurya99@users.noreply.github.com> Date: Fri, 20 Jan 2023 09:47:05 +0530 Subject: [PATCH 3/3] Update database.js --- database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database.js b/database.js index 9dda583..50ea20d 100644 --- a/database.js +++ b/database.js @@ -59,7 +59,7 @@ let db = new sqlite3.Database(DBSOURCE, (err) => { name text, address text, emai text, - dateofbirth text, + dateofBirth text, gender text, age text, cardHolderName text,