var passport = require('passport');
var path = require('path');
var { checkForFacebookUser } = require('../db/controllers/auth');
var journal = require('../db/controllers/journal'); // Controller to save and retrieve journal entries
var analytics = require('../db/controllers/analytics');

module.exports = (app) => {

  app.get('/api/journal', (req, res) => {
    journal.getJournalEntriesForDate(req, res); // get journal entries for a particular date
  });

  app.post('/api/journal', (req, res) => {
    journal.postJournalEntriesForDate(req, res); // post journal entries for a particular date
  });

  app.get('/api/analytics', (req, res) => {
    analytics.retrieveTextAnalysis(req, res);
  });

  app.post('/api/analytics', (req, res) => {
    analytics.analyzeDays(req, res);
  });

  app.get('/journal', (req, res) => {
    res.sendFile(path.resolve(__dirname, '../../dist', 'index.html'));
  });

  app.get('/dashboard', (req, res) => {
    res.sendFile(path.resolve(__dirname, '../../dist', 'index.html'));
  });

  app.get('/login', (req, res) => {
    res.sendFile(path.resolve(__dirname, '../../dist', 'index.html'));
  });

  app.get('/profile', (req, res) => {
    res.sendFile(path.resolve(__dirname, '../../dist', 'index.html'));
  });

  app.get('/auth', checkForFacebookUser);

  app.get('/logout', (req, res) => { 
    req.logout();
    res.redirect('/');
  });

  app.get('/auth/facebook',
    passport.authenticate('facebook')
  );

  // handle the callback after facebook has authenticated the user
  app.get('/auth/facebook/callback',
    passport.authenticate('facebook', {
      successRedirect: 'http://localhost:3000/journal',
      failureRedirect: 'http://localhost:3000/login'
    })
  );
  
  app.get('/auth/amazon',
    passport.authenticate('amazon', { scope: ['profile'] })
  );

  // handle the callback after facebook has authenticated the user
  app.get('/auth/amazon/callback',
    passport.authenticate('amazon', {
      successRedirect: 'http://localhost:3000/journal',
      failureRedirect: 'http://localhost:3000/login'
    })
  );
}
@@ -733,32 +733,542 @@
 (req, res) =%3E %7B%0A
+    // POST request to '/api/analytics/' tells server to run analytics%0A    // on journal entries for days that we have not run analytics%0A    // yet (or for days where user has updated the journal entry)%0A%0A    // We keep track of this by saving the day to analyze%0A    // in the 'daysToBeAnalyzed' object saved in the user table%0A%0A    // We also throttle the api calls to once every 12 hours%0A    // by making sure we are at least 12 hours ahead of the%0A    // 'timeOfLastAnalysis' datetime saved in the user table%0A%0A
     analytics.an
@@ -1279,32 +1279,33 @@
 eDays(req, res);
+ 
 %0A  %7D);%0A%0A  app.ge

Update comments in post request for /api/analytics