var express = require('express');
var router = express.Router();
var db = require('../models');
var User = db.User;
var Messages = db.Messages;
var Session = db.Session;
var lib = require('../lib');

/* GET home page. */
router.get('/add/:id', async function(req, res, next) {
  var id = req.params.id;
  console.log(req.cookies.sessionid);
  var sessionId = req.cookies.sessionid;
  var user = await lib.getAuthUser(sessionId);
  if(user) {
    var follow = await user.addFollow(id);
    res.send(follow);
  } else {
    res.redirect('/login');
  }
});

router.get('/get', async function(req, res, next) {
  var id = req.params.id;
  console.log(req.cookies.sessionid);
  var sessionId = req.cookies.sessionid;
  var user = await lib.getAuthUser(sessionId);
  if(user) {
    var follow = await user.getFollow({
      attributes: ['id']
    });
    res.send(follow);
  } else {
    res.redirect('/login');
  }
});

module.exports = router;
