index.js 2.76 KB
var express    = require('express');
var mysql      = require('mysql');
var dbconfig   = require('../config/database.js');
var dbconfig2  = require('../config/database2.js');
var dbconfig3  = require('../config/database3.js');
var pool = mysql.createPool(dbconfig3);
var bodyParser = require('body-parser');

var router = express.Router();

// configuration ===============================================================
router.get('/first',function(req,res){
  res.render('first',{title : "첫번째 화면"});
})

router.get('/', function(req, res){
  res.render('index',{title: "첫화면"});
});

router.get('/reservation',function(req,res){
  res.render('reservation',{title : "예약"});
});


router.post('/reservation',function(req, res){
  var creater_id = req.body.creater_id;
  var phone = req.body.phone;
  var email = req.body.email;
  var num = req.body.num;
  var restime = req.body.restime;
  var resmin = req.body.resmin;
  var date = req.body.date;

  var content = req.body.content;
    var food = req.body.food;
  pool.getConnection(function (err, connection)
     {
         // Use the connection
         var sqlForInsertBoard = "insert into menu(creater_id, phone, email, num, restime, resmin,date,food,content) values('"+creater_id+"', '"+phone+"', '"+email+"','"+num+"','"+restime+"','"+resmin+"','"+date+"','"+food+"','"+content+"')";
         connection.query(sqlForInsertBoard, function (err, rows) {
             if (err) console.error("err : " + err);
             console.log("rows : " + JSON.stringify(rows));
             res.redirect('/resconfirm');
             connection.release();
             // Don't use the connection here, it has been returned to the pool.
         });
     });
})

router.get('/resconfirm', function(req, res){
  res.render('resconfirm',{title : "예약확인"});
});


router.get('/menu',function(req,res){
  res.render('menu',{title : "메뉴판"});
});

router.get('/db', function(req, res){
  pool.getConnection(function (err, connection)
     {
         // Use the connection
         //var sqlForInsertBoard = "insert into menu(creater_id, phone, email, num, restime, resmin,date,food,content) values('"+creater_id+"', '"+phone+"', '"+email+"','"+num+"','"+restime+"','"+resmin+"','"+date+"','"+food+"','"+content+"')";
         var sqlForSelect = 'SELECT * from menu'
         connection.query(sqlForSelect, function (err, rows) {
             if (err) console.error("err : " + err);
             console.log("rows : " + JSON.stringify(rows));
             res.render('first');
             connection.release();
             // Don't use the connection here, it has been returned to the pool.
         });
     });
});


/* GET home page. */
router.get('/pay', function(req, res, next) {
  res.render('pay', { title: '결제' });
});

module.exports = router;