-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateCatteryPage.js
More file actions
31 lines (29 loc) · 939 Bytes
/
Copy pathCreateCatteryPage.js
File metadata and controls
31 lines (29 loc) · 939 Bytes
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
module.exports = function(){
var express = require('express');
var router = express.Router();
router.post('/', function(req, res){
if (!req.session.loggedin)
{
console.log("Can't create cattery, user is not logged in");
return;
}
var mysql = req.app.get('mysql');
var inserts = [req.body.catteryname, req.session.userID];
var sql = "INSERT INTO cattery (name, own_id) VALUES (?, ?);"
mysql.pool.query(sql, inserts, function(err, results, fields){
if(err){
console.log(JSON.stringify(error))
res.write(JSON.stringify(error));
res.end();
//return;
}
else {
res.redirect('/CatteriesPage');
}
})
});
router.get('/', function(req, res){
res.render('CreateCatteryPage');
});
return router;
}();