const express = require('express')
const bodyParser = require('body-parser');
const path = require('path');
const model = require('../db/mongoose-schemas.js')
const app = express();
var logger = require('morgan');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(express.static(path.join(__dirname, '../client')));

app.use(logger('dev'));

//HANDLE GET REQUESTS

app.get('/users', function(req, res) {
  var users = [];
  model.User.find({}, function(err, user) {
    if (err) console.log(err);
    users.push(user);
  })
  .then(function() {
    console.log(users);
    res.send(users);
  });
});

app.get('/templates', function(req, res) {
  var templates = [];

  model.Template.find({}, function(err, template) {
    if (err) console.log(err);
    templates.push(template);
  })
  .then(function() {
    console.log(templates);
    res.send(templates);
  });
});

app.get('/activities', function(req, res) {
  var activities = [];

  model.Activity.find({}, function(err, activity) {
    if (err) console.log(err);
    activities.push(activity);
  })
  .then(function() {
    console.log(activities);
    res.send(activities);
  });
});

app.get('/histories', function(req, res) {
  var histories = [];

  model.History.find({}, function(err, history) {
    if (err) console.log(err);
    Histories.push(history);
  })
  .then(function() {
    console.log(histories);
    res.send(histories);
  });
});

//HANDLE POST REQUESTS

app.post('/users', function(req, res) {
  console.log(req.body);
  model.User.create(req.body);
  res.send('Posted User');
});

app.post('/templates', function(req, res) {
  console.log(req.body);
  model.Template.create(req.body);
  res.send('Posted Template');
});

app.post('/activities', function(req, res) {
  console.log(req.body);
  model.Activity.create(req.body);
  res.send('Posted Activity');
});

app.post('/histories', function(req, res) {
  console.log(req.body);
  model.History.create(req.body);
  res.send('Posted History');
});

app.listen(3000, function() {
  console.log('connected to http://localhost:3000');
});

@@ -175,19 +175,21 @@
 ress();%0A
-var
+const
  logger 
@@ -209,16 +209,59 @@
 rgan');%0A
+const PORT = 3000;%0A%0Aapp.use(logger('dev'));
 %0Aapp.use
@@ -395,39 +395,16 @@
 t')));%0A%0A
-app.use(logger('dev'));
 %0A%0A//HAND
@@ -2047,20 +2047,20 @@
 .listen(
-3000
+PORT
 , functi
@@ -2080,17 +2080,17 @@
 ole.log(
-'
+%60
 connecte
@@ -2115,13 +2115,16 @@
 ost:
-3000'
+$%7BPORT%7D%60
 );%0A%7D

Create Port Variable. Refactor Complete.