Skip to content

Commit

Permalink
Merge a6e46f2 into b3db8f3
Browse files Browse the repository at this point in the history
  • Loading branch information
iidrees committed Apr 30, 2018
2 parents b3db8f3 + a6e46f2 commit 8b8f330
Show file tree
Hide file tree
Showing 70 changed files with 3,805 additions and 1,757 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gulpfile.babel.js
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MONGOHQ_URL=<THE MONGODB LOCALHOST URL>
MONGOHQ_URL_TEST=<THE MONGODB LOCALHOST TEST URL>
LOGIN_URL=<URL OF STAGING OR REVIEW SIGNIN PAGE>

SECRET=<YOUR JWT SECRET>

Expand All @@ -18,3 +19,6 @@ GOOGLE_CALLBACK_URL=<GOOGLE_CALLBACK_URL>
GITHUB_CLIENT_ID=<GITHUB_CLIENT_ID>
GITHUB_CLIENT_SECRET=<GITHUB_CLIENT_SECRET>
GITHUB_CALLBACK_URL=<GITHUB_CALLBACK_URL

EMAIL=<GMAIL_ADDRESS>
EMAIL_PASSWORD=<GMAIL_PASSWORD>
19 changes: 11 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
"env": {
"node": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 6
"mocha": true,
"jquery": true,
"browser": true
},
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"max-len": [1, 80, 4],
"max-len": [1, 80, 4, { "ignoreStrings": true }],
"new-cap": 0,
"no-useless-escape": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"no-underscore-dangle": 0,
"eqeqeq": 0,
"func-names": 0,
"curly": ["error", "multi-line"],
"import/extensions": "off",
"import/no-unresolved": "off",
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"valid-jsdoc": [
"error",
Expand All @@ -37,8 +42,6 @@
"ClassDeclaration": true
}
}
],
"import/extensions": "off",
"import/no-unresolved": "off"
]
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dist
.env
coverage/
.nyc_output
.idea
testdb
.idea
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/andela/nazgul-cfh.svg?branch=develop)](https://travis-ci.org/andela/nazgul-cfh)
[![Coverage Status](https://coveralls.io/repos/github/andela/nazgul-cfh/badge.svg?branch=chore%2F156100320%2Fintegrate-coveralls)](https://coveralls.io/github/andela/nazgul-cfh?branch=develop)
[![Coverage Status](https://coveralls.io/repos/github/andela/nazgul-cfh/badge.svg?branch=develop)](https://coveralls.io/github/andela/nazgul-cfh?branch=develop)

# Cards for Humanity - [http://cfh.io](http://cfh.io)

Cards for Humanity is a fast-paced online version of the popular card game, Cards Against Humanity, that gives you the opportunity to donate to children in need - all while remaining as despicable and awkward as you naturally are.
Expand Down
77 changes: 46 additions & 31 deletions app/controllers/answers.js
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);
});
};
};
47 changes: 47 additions & 0 deletions app/controllers/game.js
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;
16 changes: 8 additions & 8 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ var mongoose = require('mongoose'),
/**
* Redirect users to /#!/app (forcing Angular to reload the page)
*/
exports.play = function(req, res) {
if (Object.keys(req.query)[0] === 'custom') {
res.redirect('/#!/app?custom');
} else {
res.redirect('/#!/app');
exports.play = (req, res) => {
let { region, custom } = req.query;
if (custom !== 'true') custom = false;
if (!region) {
const regions = ['africa', 'asia'];
region = regions[Math.floor(Math.random() * 2)];
}
res.redirect(`/#!/app?custom=${custom}&region=${region}`);
};

exports.render = function(req, res) {
res.render('index', {
user: req.user ? JSON.stringify(req.user) : "null"
});
res.render('index');
};
75 changes: 46 additions & 29 deletions app/controllers/questions.js
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);
});
};
Loading

0 comments on commit 8b8f330

Please sign in to comment.