-
Notifications
You must be signed in to change notification settings - Fork 18
/
issues.js
62 lines (52 loc) · 1.72 KB
/
issues.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
var logger = require('./log');
exports.all = function (req, res) {
req.getConnection(function(err, connection){
connection.query("select * from issues", function(err, results){
res.render('issues', {issues : results})
});
});
}
exports.get = function (req, res) {
req.getConnection(function(err, connection){
connection.query("select * from issues where id = ?", req.params.id, function(err, results){
console.log(results);
return res.render('issue_edit', {issue : results[0]})
});
});
}
exports.update = function (req, res) {
req.getConnection(function(err, connection){
var data = {
heading : req.body.heading,
description : req.body.description
};
connection.query("update issues set ? where id = ?", [data, req.params.id], function(err, results){
// what will happen here?
return res.redirect("/issues");
});
});
}
exports.showAdd = function (req, res) {
res.render('isue')
}
exports.add = function (req, res) {
var data = {
heading : req.body.heading,
description : req.body.description
}
req.getConnection(function(err, connection){
// what can I do better here?
connection.query("insert into issues set ?", data, function(err, results){
// what can I do better here?
res.redirect('/issues')
});
});
}
exports.delete = function (req, res, next) {
req.getConnection(function(err, connection){
connection.query("delete from isues where id = ?", req.params.id, function(err, results){
//if (err) return next(err);
res.redirect('/issues')
});
});
}