Skip to content

Commit

Permalink
Merge pull request #244 from IGME-Research-Studio/release-0-3-0-adden…
Browse files Browse the repository at this point in the history
…dum-addendum

Release 0 3 0 addendum addendum 🚀 🚀 🚀 🚀 🚀
  • Loading branch information
dropofwill committed Apr 13, 2016
2 parents 9929091 + dcc9845 commit a61ae97
Show file tree
Hide file tree
Showing 72 changed files with 3,999 additions and 810 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"presets": ["es2015"]
"presets": ["es2015", "stage-0"],
"retainLines": true
}
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"extends": "airbnb/base",
"ecmaFeatures": { "destructuring": true },
"rules": {
"brace-style": [2, "stroustrup", { "allowSingleLine": true }],
"no-param-reassign": 1,
"no-unused-vars": [2, {"args": "after-used", "argsIgnorePattern": "^__"}],
"no-shadow": 1,
"default-case": 1,
"new-cap": 0,
Expand Down
8 changes: 4 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require('babel-core/register');
require('babel-core/register')({plugins: ['rewire']});

module.exports = function (grunt) {
'use strict';

var testFiles = ['test/unit/**/*.js'],
srcFiles = ['api/**/*.js'],
jsFiles = srcFiles.concat(testFiles);
var testFiles = ['test/unit/**/*.js'];
var srcFiles = ['api/**/*.js'];
var jsFiles = srcFiles.concat(testFiles);

// Set test environment here for cross-platform
process.env.NODE_ENV='test';
Expand Down
10 changes: 2 additions & 8 deletions api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import logger from 'morgan';
import cors from 'cors';
import addStatusCodes from 'express-json-status-codes';
import log from 'winston';
// import redis from 'ioredis';

import CFG from '../config';
import routes from './routes';
import dispatcher from './dispatcher';
import database from './services/database';
import database from './helpers/database';

// const redisClient = Redis(CFG.redisURL);
const extendedExpress = addStatusCodes(express);
log.level = CFG.logLevel;

Expand All @@ -22,7 +20,7 @@ const setupApp = function() {
.use(logger('dev'))
.use(compression())
.use(cors())
.use(bodyParser.urlencoded({extended: true}))
.use(bodyParser.json())
.use(enrouten(routes))
.disable('x-powered-by')
.listen(CFG.port, function(err) {
Expand All @@ -32,11 +30,7 @@ const setupApp = function() {
};

database();

const app = setupApp();
dispatcher(app);

database();

export { app };

41 changes: 41 additions & 0 deletions api/constants/EXT_EVENT_API.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {

JOIN_ROOM: 'JOIN_ROOM',
LEAVE_ROOM: 'LEAVE_ROOM',
UPDATE_BOARD: 'UPDATE_BOARD',

CREATE_IDEA: 'CREATE_IDEA',
DESTROY_IDEA: 'DESTROY_IDEA',
Expand All @@ -25,13 +26,43 @@ module.exports = {
REMOVE_IDEA: 'REMOVE_IDEA',
GET_COLLECTIONS: 'GET_COLLECTIONS',

START_TIMER: 'START_TIMER',
DISABLE_TIMER: 'DISABLE_TIMER',

ENABLE_IDEAS: 'ENABLE_IDEAS',
DISABLE_IDEAS: 'DISABLE_IDEAS',
FORCE_VOTE: 'FORCE_VOTE',
FORCE_RESULTS: 'FORCE_RESULTS',
GET_STATE: 'GET_STATE',
GET_OPTIONS: 'GET_OPTIONS',

GET_USERS: 'GET_USERS',

// Past-tense responses
RECEIVED_STATE: 'RECEIVED_STATE',
RECEIVED_OPTIONS: 'RECEIVED_OPTIONS',

RECEIVED_CONSTANTS: 'RECEIVED_CONSTANTS',
RECEIVED_IDEAS: 'RECEIVED_IDEAS',
RECEIVED_COLLECTIONS: 'RECEIVED_COLLECTIONS',

JOINED_ROOM: 'JOINED_ROOM',
LEFT_ROOM: 'LEFT_ROOM',
UPDATED_BOARD: 'UPDATED_BOARD',

STARTED_TIMER: 'STARTED_TIMER',
DISABLED_TIMER: 'DISABLED_TIMER',
TIMER_EXPIRED: 'TIMER_EXPIRED',
GET_TIME: 'GET_TIME',
RECEIVED_TIME: 'RECEIVED_TIME',

ENABLED_IDEAS: 'ENABLED_IDEAS',
DISABLED_IDEAS: 'DISABLE_IDEAS',
FORCED_VOTE: 'FORCED_VOTE',
FORCED_RESULTS: 'FORCED_RESULTS',

READY_TO_VOTE: 'READY_TO_VOTE',
FINISHED_VOTING: 'FINISHED_VOTING',

UPDATED_IDEAS: 'UPDATED_IDEAS',
UPDATED_COLLECTIONS: 'UPDATED_COLLECTIONS',
Expand All @@ -42,4 +73,14 @@ module.exports = {
REMOVED_ADMIN: 'REMOVED_ADMIN',
ADDED_PENDING_USER: 'ADDED_PENDING_USER',
REMOVED_PENDING_USER: 'REMOVED_PENDING_USER',
RECEIVED_USERS: 'RECEIVED_USERS',

GET_VOTING_ITEMS: 'GET_VOTING_ITEMS',
RECEIVED_VOTING_ITEMS: 'RECEIVED_VOTING_ITEMS',
VOTE: 'VOTE',
VOTED: 'VOTED',
READY_USER: 'READY_USER',
READIED_USER: 'READIED_USER',
GET_RESULTS: 'GET_RESULTS',
RECEIVED_RESULTS: 'RECEIVED_RESULTS',
};
16 changes: 9 additions & 7 deletions api/controllers/v1/auth/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
* Validates a given token, returns the Mongo user object
*/

import { isNull } from '../../../services/ValidatorService';
import { values } from 'ramda';
import { verify } from '../../../services/TokenService';
import { JsonWebTokenError } from 'jsonwebtoken';
import { anyAreNil } from '../../../helpers/utils';

export default function validate(req, res) {
const userToken = req.body.userToken;
const { userToken } = req.body;
const required = { userToken };

if (isNull(userToken)) {
return res.badRequest(
{message: 'Not all required parameters were supplied'});
if (anyAreNil(values(required))) {
return res.badRequest({ ...required,
message: 'Not all required parameters were supplied'});
}

return verify(userToken)
Expand All @@ -24,7 +26,7 @@ export default function validate(req, res) {
return res.unauthorized({error: err, message: 'Invalid userToken'});
})
.catch((err) => {
return res.internalServerError(
{error: err, message: 'Something went wrong on ther server'});
return res.internalServerError({error: err,
message: 'Something went wrong on the server'});
});
}
22 changes: 18 additions & 4 deletions api/controllers/v1/boards/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
*
*/

import boardService from '../../../services/BoardService';
import { values } from 'ramda';
import { verifyAndGetId } from '../../../services/TokenService';
import { create as createBoard } from '../../../services/BoardService';
import { anyAreNil } from '../../../helpers/utils';

export default function create(req, res) {
boardService.create()
.then((boardId) => res.created({boardId: boardId}))
.catch((err) => res.serverError(err));
const { userToken, boardName, boardDesc } = req.body;
const required = { userToken };

if (anyAreNil(values(required))) {
return res.badRequest({ ...required,
message: 'Not all required parameters were supplied'});
}

return verifyAndGetId(userToken)
.then((userId) => {
return createBoard(userId, boardName, boardDesc)
.then((boardId) => res.created({boardId: boardId}))
.catch((err) => res.serverError(err));
});
}
14 changes: 8 additions & 6 deletions api/controllers/v1/boards/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/

import { values } from 'ramda';
import boardService from '../../../services/BoardService';
import { isNull } from '../../../services/ValidatorService';
import { anyAreNil } from '../../../helpers/utils';

export default function destroy(req, res) {
const boardId = req.param('boardId');
const { boardId } = req.body;
const required = { boardId };

if (isNull(boardId)) {
return res.badRequest(
{message: 'Not all required parameters were supplied'});
if (anyAreNil(values(required))) {
return res.badRequest({ ...required,
message: 'Not all required parameters were supplied'});
}

boardService.destroy(boardId)
return boardService.destroy(boardId)
.then(() => res.ok({boardId: boardId}))
.catch((err) => res.serverError(err));
}
18 changes: 11 additions & 7 deletions api/controllers/v1/users/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
*
*/

import { values } from 'ramda';
import userService from '../../../services/UserService';
import { isNull } from '../../../services/ValidatorService';
import { anyAreNil } from '../../../helpers/utils';

export default function create(req, res) {
const username = req.body.username;
const { username } = req.body;
const required = { username };

if (isNull(username)) {
return res.badRequest(
{message: 'Not all required parameters were supplied'});
if (anyAreNil(values(required))) {
return res.badRequest({...required,
message: 'Not all required parameters were supplied'});
}

userService.create(username)
.then((user) => res.created(user))
return userService.create(username)
.then(([token, user]) => (
res.created({token: token, username: username, userId: user.id})
))
.catch((err) => {
res.internalServerError(err);
});
Expand Down
Loading

0 comments on commit a61ae97

Please sign in to comment.