-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
3,805 additions
and
1,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gulpfile.babel.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ dist | |
.env | ||
coverage/ | ||
.nyc_output | ||
.idea | ||
testdb | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,70 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var mongoose = require('mongoose'), | ||
async = require('async'), | ||
Answer = mongoose.model('Answer'), | ||
_ = require('underscore'); | ||
const mongoose = require('mongoose'); | ||
|
||
const Answer = mongoose.model('Answer'); | ||
|
||
/** | ||
* Find answer by id | ||
* @param {object} req | ||
* @param {object} res | ||
* @param {functio} next | ||
* @param {integer} id | ||
* @returns { void } | ||
*/ | ||
exports.answer = function(req, res, next, id) { | ||
Answer.load(id, function(err, answer) { | ||
if (err) return next(err); | ||
if (!answer) return next(new Error('Failed to load answer ' + id)); | ||
req.answer = answer; | ||
next(); | ||
}); | ||
exports.answer = function (req, res, next, id) { | ||
Answer.load(id, (err, answer) => { | ||
if (err) return next(err); | ||
if (!answer) return next(new Error(`Failed to load answer ${id}`)); | ||
req.answer = answer; | ||
next(); | ||
}); | ||
}; | ||
|
||
/** | ||
* Show an answer | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns { void } | ||
*/ | ||
exports.show = function(req, res) { | ||
res.jsonp(req.answer); | ||
exports.show = function (req, res) { | ||
res.jsonp(req.answer); | ||
}; | ||
|
||
/** | ||
* List of Answers | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns { void } | ||
*/ | ||
exports.all = function(req, res) { | ||
Answer.find({official:true}).select('-_id').exec(function(err, answers) { | ||
if (err) { | ||
res.render('error', { | ||
status: 500 | ||
}); | ||
} else { | ||
res.jsonp(answers); | ||
} | ||
exports.all = function (req, res) { | ||
Answer.find({ official: true }) | ||
.select('-_id') | ||
.exec((err, answers) => { | ||
if (err) { | ||
res.render('error', { | ||
status: 500 | ||
}); | ||
} else { | ||
res.jsonp(answers); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* List of Answers (for Game class) | ||
* fetches all answers | ||
* @param { string } region | ||
* @param { function } cb | ||
* @returns { void } | ||
*/ | ||
exports.allAnswersForGame = function(cb) { | ||
Answer.find({official:true}).select('-_id').exec(function(err, answers) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
cb(answers); | ||
} | ||
exports.allAnswersForGame = function (region, cb) { | ||
Answer.find({ | ||
region, | ||
official: true | ||
}) | ||
.select('-_id') | ||
.exec((err, answers) => { | ||
cb(answers); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable import/no-unresolved, import/extensions */ | ||
import mongoose from 'mongoose'; | ||
|
||
const GameHistory = mongoose.model('GameHistory'); | ||
|
||
/* Save Game History */ | ||
|
||
/** | ||
* @class Game | ||
*/ | ||
class Game { | ||
/** | ||
* @static | ||
* @param {any} req JSON request | ||
* @param {any} res JSON response | ||
* @returns {any} any | ||
* @memberof Game | ||
*/ | ||
static gameHistory(req, res) { | ||
const { gameLog } = req.body; | ||
|
||
if (!gameLog) { | ||
return res.status(422).send({ | ||
errors: 'No data supplied' | ||
}); | ||
} | ||
const GameLog = new GameHistory({ | ||
gameID: gameLog.gameId, | ||
gamePlayers: gameLog.players, | ||
gameRound: gameLog.rounds, | ||
gameWinner: gameLog.gameWinner.username | ||
}); | ||
|
||
GameLog.save((err) => { | ||
if (err) { | ||
return res.status(422).send({ | ||
errors: err.errors | ||
}); | ||
} | ||
return res.status(201).send({ | ||
message: 'Game history successfully saved' | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
export default Game; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,72 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var mongoose = require('mongoose'), | ||
async = require('async'), | ||
Question = mongoose.model('Question'), | ||
_ = require('underscore'); | ||
|
||
const mongoose = require('mongoose'); | ||
|
||
const Question = mongoose.model('Question'); | ||
|
||
/** | ||
* Find question by id | ||
* @param { object } req | ||
* @param { object } res | ||
* @param { function } next | ||
* @param { integer } id | ||
* @returns { void } | ||
*/ | ||
exports.question = function(req, res, next, id) { | ||
Question.load(id, function(err, question) { | ||
if (err) return next(err); | ||
if (!question) return next(new Error('Failed to load question ' + id)); | ||
req.question = question; | ||
next(); | ||
}); | ||
exports.question = function (req, res, next, id) { | ||
Question.load(id, (err, question) => { | ||
if (err) return next(err); | ||
if (!question) return next(new Error(`Failed to load question ${id}`)); | ||
req.question = question; | ||
next(); | ||
}); | ||
}; | ||
|
||
/** | ||
* Show an question | ||
* @param { object } req | ||
* @param { object } res | ||
* @returns { void } | ||
*/ | ||
exports.show = function(req, res) { | ||
res.jsonp(req.question); | ||
exports.show = function (req, res) { | ||
res.jsonp(req.question); | ||
}; | ||
|
||
/** | ||
* List of Questions | ||
* @param { object } req | ||
* @param { object } res | ||
* @returns { void } | ||
*/ | ||
exports.all = function(req, res) { | ||
Question.find({official:true, numAnswers: {$lt : 3}}).select('-_id').exec(function(err, questions) { | ||
if (err) { | ||
res.render('error', { | ||
status: 500 | ||
}); | ||
} else { | ||
res.jsonp(questions); | ||
} | ||
exports.all = function (req, res) { | ||
Question.find({ official: true, numAnswers: { $lt: 3 } }) | ||
.select('-_id') | ||
.exec((err, questions) => { | ||
if (err) { | ||
res.render('error', { | ||
status: 500 | ||
}); | ||
} else { | ||
res.jsonp(questions); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* List of Questions (for Game class) | ||
* @param { string } region | ||
* @param { function } cb | ||
* @returns { void } | ||
*/ | ||
exports.allQuestionsForGame = function(cb) { | ||
Question.find({official:true, numAnswers: {$lt : 3}}).select('-_id').exec(function(err, questions) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
cb(questions); | ||
} | ||
exports.allQuestionsForGame = function (region, cb) { | ||
Question.find({ | ||
region, | ||
official: true, | ||
numAnswers: { $lt: 3 } | ||
}) | ||
.select('-_id') | ||
.exec((err, questions) => { | ||
cb(questions); | ||
}); | ||
}; |
Oops, something went wrong.