-
Notifications
You must be signed in to change notification settings - Fork 14
/
actions.js
62 lines (62 loc) · 1.68 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module.exports = {
InsertContact : function (req, res, pool){
pool.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
pool.cql("INSERT INTO contact (email, name, phone, address, city) VALUES (?,?,?,?,?)", [post.email, post.name, post.phone, post.address, post.city], function(err, results){
res.redirect('/');
});
}
});
},
UpdateContact : function (req, res, pool){
pool.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
pool.cql("UPDATE contact SET name = ?, phone = ?, address = ?, city = ? WHERE email = ?", [post.name, post.phone, post.address, post.city, post.contactEdit], function(err, results){
res.redirect('/');
});
}
});
},
DeleteContact : function (req, res, pool){
pool.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
pool.cql("DELETE FROM contact WHERE email = ?", [post.contactDel], function(err, results){
res.redirect('/');
});
}
});
},
LoadContacts : function (req, res, pool){
pool.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
var query = "SELECT * FROM contact";
if(typeof(req.query.email) != "undefined"){
query += " WHERE email = '"+req.query.email+"'";
}
pool.cql(query, [], function(err, results){
var data = [];
results.forEach(function(row){
var obj = {};
row.forEach(function(name,value,ts,ttl){
obj[name] = value;
});
data.push(obj);
});
res.send(data);
});
}
});
}
}