<commit_before>'use strict';

const express = require('express');
const PORT = process.env.PORT || 3000;
const proxyRequest = require('express-request-proxy');
//bodyParser help returning json objects
const bodyParser = require('body-parser');
//requiring super agent for back end node
let request = require('superagent');

// This will choose the correct scheme given the plattomr. darwin here means mac.
let localdbURL = 'postgres://' + (process.platform === 'darwin' ? '' : `postgres:${process.env.PG_PASSWORD}@`) + 'localhost:5432/kilovolt'

const DATABASE_URL = process.env.DATABASE_URL || localdbURL;
//requiring pg: your postgres
const pg = require('pg');

//create a new a dabase clien with our connection string: linking it togather
const dbClient = new pg.Client(DATABASE_URL);
//connect it immediatly
dbClient.connect();
//check db for errors
dbClient.on('error', function(err) {
  console.error(err);
})

const app = express();

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

app.use(express.static('.'));

app.get('/github/*', function(req, res) {
  let headers = process.env.GITHUB_TOKEN ? {
    Authorization: `token ${process.env.GITHUB_TOKEN}`
  } : {};
  let url = `${req.params[0]}`;
  (proxyRequest({
    url: url,
    headers: headers
  }))(req, res);
})

//POST FOVORITES TO FAVORITES TABLE
app.post('/addFavorite', function(req, res) {
  dbClient.query(
    `INSERT INTO favorites (userid, movieid, dateliked) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING;`, [req.headers.userid, req.headers.movieid, new Date()]
  ).then(() => res.send('Update complete')).catch(() => res.send('Update failed'))
})

function getMoviesFromApi() {
  request.get(`https://api.themoviedb.org/3/movie/now_playing?api_key=${process.env.MOVIEDBTOKEN}&language=en-US&page=1`).end(function(err, res) {
    processMoviesResponse(res.body)
  })
}


// GET ALL FAVORITES LIKES

app.get('/getUserFavorites',function(req,res){
  dbClient.query(
    'SELECT * from favorites;'
)<commit_msg>Added getPeopleMoviesFavCount<commit_after>'use strict';

const express = require('express');
const PORT = process.env.PORT || 3000;
const proxyRequest = require('express-request-proxy');
//bodyParser help returning json objects
const bodyParser = require('body-parser');
//requiring super agent for back end node
let request = require('superagent');

// This will choose the correct scheme given the plattomr. darwin here means mac.
let localdbURL = 'postgres://' + (process.platform === 'darwin' ? '' : `postgres:${process.env.PG_PASSWORD}@`) + 'localhost:5432/kilovolt'

const DATABASE_URL = process.env.DATABASE_URL || localdbURL;
//requiring pg: your postgres
const pg = require('pg');

//create a new a dabase clien with our connection string: linking it togather
const dbClient = new pg.Client(DATABASE_URL);
//connect it immediatly
dbClient.connect();
//check db for errors
dbClient.on('error', function(err) {
  console.error(err);
})

const app = express();

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

app.use(express.static('.'));

app.get('/github/*', function(req, res) {
  let headers = process.env.GITHUB_TOKEN ? {
    Authorization: `token ${process.env.GITHUB_TOKEN}`
  } : {};
  let url = `${req.params[0]}`;
  (proxyRequest({
    url: url,
    headers: headers
  }))(req, res);
})

app.get('/getPeopleMoviesFavCount', function(req, res) {
  dbClient.query(
    `SELECT userid,  movieid, COUNT(*) FROM favorites GROUP BY userid, movieid;`
  )
  .then(results => res.send(results.rows))
  .catch(console.error);
});

//POST FOVORITES TO FAVORITES TABLE
app.post('/addFavorite', function(req, res) {
  dbClient.query(
    `INSERT INTO favorites (userid, movieid, dateliked) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING;`, [req.headers.userid, req.headers.movieid, new Date()]
  ).then(() => res.send('Update complete')).catch(() => res.send('Update failed'))
})

function getMoviesFromApi() {
  request.get(`https://api.themoviedb.org/3/movie/now_playing?api_key=${process.env.MOVIEDBTOKEN}&language=en-US&page=1`).end(function(err, res) {
    processMoviesResponse(res.body)
  })
}


// GET ALL FAVORITES LIKES

app.get('/getUserFavorites',function(req,res){
  dbClient.query(
    'SELECT * from favorites;'
)
{'fraction_non_alphanumeric': 0.166160317831269, 'fraction_numerical': 0.006543584949754616, 'mean_word_length': 4.854993160054719, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '587727', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1444, 'n_words': 342}