calendar.js 1.14 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.access_token) return res.redirect('/auth/google');
  else 
  var accessToken = req.session.access_token;
  //getAllcalendarID(accessToken);
  //console.log(calList);
  //getAllCalendars(accessToken);
  //console.log(Calendars);
  gcal(accessToken).calendarList.list(function(err,data){
    if(err) return console.log(err);
    else {
      calList = data.items;
      //console.log(calList);
      res.render('calendar',{calList:calList,accessToken:accessToken});
    }
  });
});


module.exports = router;

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