calendar.js 1.08 KB
var express = require('express');
var router = express.Router();
var gcal = require('google-calendar');

router.post('/calendar',function(req,res,next){
    var id = req.body.id;
    res.render('calendar',{id: id});
});
//router.get('/',function(req,res,next){
  //var accessToken = req.session.access_token;
  //gcal(accessToken).calendarList.list(function(err,data){
  //if(err) return res.send(err);
  //return res.render('calendar',{calendars : data});
  //});
  //res.render('calendar',{id:1});
  console.log(1);
//})

calList = new Array();

router.get('/', function(req, res, next) {
  if(!req.session.googleToken) return res.redirect('/auth/google');
  else 

  googleToken = req.session.googleToken;
  kakaoToken = req.session.kakaoToken;

  gcal(googleToken).calendarList.list(function(err,data){
    if(err) return console.log(err);
    else {
      calList = data.items;
      //console.log(calList);
      res.render('calendar',{calList:calList,googleToken:googleToken,kakaoToken:kakaoToken});
    }
  });
});


module.exports = router;

//db에서 calendar id에 해당하는 이벤트 출력