aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131/hw7/dbio.js
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2021-04-30 21:35:25 -0500
committerMatthew Strapp <msattr@gmail.com>2021-04-30 21:35:25 -0500
commit2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9 (patch)
treea397c151b8378e179609fdde2d59a8c037091c70 /csci4131/hw7/dbio.js
parentRearrange, add old contacts page because other is "copyrighted" (diff)
downloadhomework-2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9.tar
homework-2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9.tar.gz
homework-2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9.tar.bz2
homework-2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9.tar.lz
homework-2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9.tar.xz
homework-2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9.tar.zst
homework-2b37edf1e2f0b4a5e931b94de422e5bfc1ca1fa9.zip
Finish HW
Diffstat (limited to 'csci4131/hw7/dbio.js')
-rw-r--r--csci4131/hw7/dbio.js64
1 files changed, 56 insertions, 8 deletions
diff --git a/csci4131/hw7/dbio.js b/csci4131/hw7/dbio.js
index dcc7386..96faf93 100644
--- a/csci4131/hw7/dbio.js
+++ b/csci4131/hw7/dbio.js
@@ -53,9 +53,7 @@ function getContacts() {
return new Promise (function(resolve, reject) {
let conTab = []
connection.query('SELECT * FROM tbl_contacts', function (err, rows, fields) {
- if (err) {
- return reject(err);
- }
+ if (err) throw err;
resolve(rows);
});
});
@@ -68,16 +66,64 @@ function addContacts(contact) {
location: contact.location,
contact_info: contact.contact,
email: contact.email,
- website_url: contact.website_name,
+ website: contact.website,
}
- return new Promise(function(resolve, reject) {
- connection.query('INSERT tbl_contacts SET ?', newCon, function (err, result) { //Parameterized insert
+ return new Promise (function (resolve, reject) {
+ connection.query('SELECT * FROM tbl_contacts where name=?', contact.name, function(err, rows, fields) {
if (err) throw err;
- console.log("Values inserted");
- resolve();
+ console.log("Table found")
+ if (rows.length > 0) {
+ // Duplicate
+ console.log("found Duplicate name!");
+ resolve(false);
+ } else {
+ connection.query('INSERT tbl_contacts SET ?', newCon, function (err, result) { //Parameterized insert
+ if (err) throw err;
+ console.log("Values inserted.");
+ resolve(true);
+ });
+ }
});
});
+}
+
+
+
+function editContact(contact) {
+ let edit = {
+ name: contact.name,
+ category: contact.category,
+ location: contact.location,
+ contact_info: contact.contact,
+ email: contact.email,
+ website: contact.website,
+ }
+ return new Promise(function (resolve, reject) {
+ connection.query('SELECT * FROM tbl_contacts where name=?', contact.name, function (err, rows, fields) {
+ if (err) throw err;
+ if (rows.length == 0) {
+ console.log("Name Changed!");
+ resolve(false);
+ } else {
+ connection.query('UPDATE tbl_contacts SET ? WHERE name=?', [edit, edit.name], function(err, result) {
+ if (err) throw err;
+ console.log("Value edited successfully?")
+ resolve(true);
+ });
+ }
+ });
+ });
+}
+
+function deleteContact(contact) {
+ return new Promise(function(resolve, reject) {
+ connection.query('DELETE FROM tbl_contacts WHERE name=?', contact, function (err, result) {
+ if (err) throw err;
+ console.log("Row deleted!")
+ resolve();
+ })
+ })
}
@@ -86,3 +132,5 @@ function addContacts(contact) {
exports.addContact = addContacts;
exports.query = passcheck;
exports.getContacts = getContacts;
+exports.deleteContact = deleteContact;
+exports.editContact = editContact;