<commit_before>require('dotenv').config();

var express = require('express');
var bodyParser = require('body-parser');
var Promise = require('bluebird');
var Models = require('./models');
var passport = require('./authentication/passport');
var morgan = require('morgan');
var session = require('express-session');
const randomBytes = Promise.promisify(require('crypto').randomBytes);
const createHash = require('crypto').createHash;
const request = require('request');

var port = process.env.PORT || 3000;
var app = express();

process.env.PWD = <PASSWORD>();
app.use(express.static(process.env.PWD + '/react-client/'));
app.use(bodyParser.json());

app.use(morgan('combined'));
app.use(session({ secret: process.env.SESSION_SECRET, resave: true, saveUninitialized: true }));
//---PASSPORT----

app.use(passport.initialize());
app.use(passport.session());

const isAuth = (req, res, next) => {
  if (req.isAuthenticated()) {
    next();
  } else {
    res.redirect('/');
  }
};

app.get('/api', (req, res ) => {
  res.send({GOOGLE_API_KEY: process.env.GOOGLE_API_KEY});
});

app.get('/user/signedIn', isAuth, (req, res) => {
  res.send(req.user);
});

app.get('/user', (req, res) => {
  Models.users.get()
    .then((result)=>{
      res.end(JSON.stringify(result));
    })
    .catch((err)=>{
      console.log('Loggin the error', err);
      res.end();
    });
});

app.post('/friend/:id', (req, res) => {
  Models.friends.addFriend(req.body.userId, req.body.friendId)
    .then(result => {
      if (!result) { throw result; }
      res.sendStatus(201);
    }).catch(() => {
      res.sendStatus(500);
    });
});

app.post('/map', (req, res) => {
  console.log('got to the post for map');
  var state = JSON.parse(req.body.state);
  state.currentCenter = `${state.currentCenter.lat}/${state.currentCenter.lng}`;
  console.log(state);
  var mapId = null;
  Models.maps.create(state)
    .then((result) => {
      mapId = result[0]['currval'];
      console.log('markers are:', state.markers);
      return Promise.map(state.markers, (marker)=>{
        var mark = {
          'lat': marker.position.lat,
          'lng': marker.position.lng,
          'mapId': parseInt(mapId),
          'info': marker.info,<commit_msg>added endpoint to get friends<commit_after>require('dotenv').config();

var express = require('express');
var bodyParser = require('body-parser');
var Promise = require('bluebird');
var Models = require('./models');
var passport = require('./authentication/passport');
var morgan = require('morgan');
var session = require('express-session');
const randomBytes = Promise.promisify(require('crypto').randomBytes);
const createHash = require('crypto').createHash;
const request = require('request');

var port = process.env.PORT || 3000;
var app = express();

process.env.PWD = process.cwd();
app.use(express.static(process.env.PWD + '/react-client/'));
app.use(bodyParser.json());

app.use(morgan('combined'));
app.use(session({ secret: process.env.SESSION_SECRET, resave: true, saveUninitialized: true }));
//---PASSPORT----

app.use(passport.initialize());
app.use(passport.session());

const isAuth = (req, res, next) => {
  if (req.isAuthenticated()) {
    next();
  } else {
    res.redirect('/');
  }
};

app.get('/api', (req, res ) => {
  res.send({GOOGLE_API_KEY: process.env.GOOGLE_API_KEY});
});

app.get('/user/signedIn', isAuth, (req, res) => {
  res.send(req.user);
});

app.get('/user', (req, res) => {
  Models.users.get()
    .then((result)=>{
      res.end(JSON.stringify(result));
    })
    .catch((err)=>{
      console.log('Loggin the error', err);
      res.end();
    });
});

app.get('/friend/:id', (req, res) => {
  Models.friends.get(req.params.id).then(list => {
    if (!list) { throw list; }
    res.send(list);
  }).catch(() => {
    res.sendStatus(404);
  });
});

app.post('/friend/:id', (req, res) => {
  Models.friends.addFriend(req.body.userId, req.body.friendId)
    .then(result => {
      if (!result) { throw result; }
      res.sendStatus(201);
    }).catch(() => {
      res.sendStatus(500);
    });
});

app.post('/map', (req, res) => {
  console.log('got to the post for map');
  var state = JSON.parse(req.body.state);
  state.currentCenter = `${state.currentCenter.lat}/${state.currentCenter.lng}`;
  console.log(state);
  var mapId = null;
  Models.maps.create(state)
    .then((result) => {
      mapId = result[0]['currval'];
      console.log('markers are:', state.markers);
      return Promise.map(state.markers, (marker)=>{
        var mark = {
          'lat': marker.position.lat,
          'lng': marker.position.lng,
          'mapId': parseInt(mapId),
          'info': marker.info,
{'fraction_non_alphanumeric': 0.211237400814926, 'fraction_numerical': 0.00536135535063264, 'mean_word_length': 3.650049850448654, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6669445', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1580, 'n_words': 288}