var express = require('express');
var request = require('request');
var router = express.Router();
var Accounts = require('../models/accounts');
var fb = require('../middleware/facebook');
var fbConfig = require('../config/fbHatModels');

router.get('/', function(req, res, next) {
  if (req.query.code) {
    request.get('https://graph.facebook.com/v2.5/oauth/access_token?client_id=' +
      process.env.FB_APP_ID + '&redirect_uri=http://localhost:3000/facebook/&client_secret=' +
      process.env.FB_APP_SECRET + '&code=' + req.query.code, function(err, response, body){
        var parsedBody = JSON.parse(body);
        Accounts.findOneAndUpdate(
          { hat_token: req.session.hatToken },
          { facebook: { user_access_token: parsedBody.access_token } },
          function(err, account) {
            res.send('Access token generated!');
          }
        );
    });
  }
});

router.get('/:nodeName/update', fb.getProviderAuthToken, fb.getDataSourceId, fb.getDataSourceModel, fb.getFbData, fb.postToHat, function(req, res, next) {
  res.send("Cool, we're done.");
});

module.exports = router;
@@ -796,24 +796,63 @@
  account) %7B%0A
+            if (err) return next(err);%0A
             
@@ -924,24 +924,682 @@
 );%0A  %7D%0A%7D);%0A%0A
+router.get('/:nodeName/init', fb.getProviderAuthToken, function(req, res, next) %7B%0A  request(%0A    %7B%0A      url: 'http://localhost:8080/data/table?access_token=' + req.account.hat_token,%0A      headers: %7B%0A        %22User-Agent%22: %22MyClient/1.0.0%22,%0A        %22Accept%22: %22application/json%22,%0A        %22Host%22: %22example.hatdex.org%22,%0A        %22Content-Type%22: %22application/json%22%0A      %7D,%0A      method: 'post',%0A      json: true,%0A      body: fbConfig%5Breq.params.nodeName%5D%0A    %7D, function(err, response, body) %7B%0A      if (err) return next(err);%0A      console.log(JSON.stringify(body));%0A      res.send(req.params.nodeName + ' source model was successfully created.');%0A    %7D);%0A%7D);%0A%0A
 router.get('

Add route to post data source models