Skip to content

Commit

Permalink
Merge branch 'backEnd' of https://github.com/lightertu/TeamDivider in…
Browse files Browse the repository at this point in the history
…to backEnd

This merge is necessary since we need to fix the sendgrid_api_key.
  • Loading branch information
kaih1994 committed Jun 7, 2017
2 parents 8551749 + 1bb38db commit d5d2056
Show file tree
Hide file tree
Showing 165 changed files with 4,579 additions and 2,734 deletions.
34 changes: 22 additions & 12 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,32 @@
"promise"
],
"env": {
"browser" : true
"browser": true
},
"globals": {
"__DEV__" : false,
"__TEST__" : false,
"__PROD__" : false,
"__COVERAGE__" : false
"__DEV__": false,
"__TEST__": false,
"__PROD__": false,
"__COVERAGE__": false
},
"rules": {
"key-spacing" : 0,
// "jsx-quotes" : [0, "prefer-single"],
"jsx-quotes" : 0,
"max-len" : [2, 120, 2],
"key-spacing": 0,
// "jsx-quotes" : [0, "prefer-single"],
"jsx-quotes": 0,
"max-len": [
2,
120,
2
],
// "object-curly-spacing" : [2, "always"],
"object-curly-spacing" : ["error", "never"],
"semi" : [2, "always"],
"indent" : 0
"object-curly-spacing": [
"error",
"never"
],
"semi": [
2,
"always"
],
"indent": 0
}
}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
"express-session": "^1.15.2",
"extract-text-webpack-plugin": "^1.0.0",
"file-loader": "^0.9.0",
"formsy-react": "^0.19.2",
"formsy-semantic-ui-react": "^0.2.4",
"fs-extra": "^1.0.0",
"html-webpack-plugin": "^2.22.0",
"http-status-codes": "^1.1.6",
Expand All @@ -112,18 +114,22 @@
"postcss-loader": "^1.1.0",
"prop-types": "^15.5.8",
"randomcolor": "^0.5.1",
"react": "^15.4.2",
"react": "^15.5.4",
"react-bootstrap": "^0.30.8",
"react-copy-to-clipboard": "^5.0.0",
"react-dnd": "^2.3.0",
"react-dnd-html5-backend": "^2.3.0",
"react-dnd-scrollzone": "^4.0.0",
"react-dom": "^15.5.4",
"react-redux": "^5.0.1",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.8",
"react-sticky": "^5.0.8",
"react-stickynode": "^1.2.1",
"react-tap-event-plugin": "^2.0.1",
"react-transition-group": "^1.1.1",
"redux": "^3.6.0",
"redux-auth-wrapper": "^1.1.0",
"redux-thunk": "^2.0.0",
"rimraf": "^2.5.4",
"sass-loader": "^4.0.0",
Expand Down
5 changes: 2 additions & 3 deletions server/models/Participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ParticipantSchema = new Schema({
type: String,
lowercase: true,
required: true,
default: ""
},

_creator: {
Expand All @@ -33,8 +32,8 @@ const ParticipantSchema = new Schema({
},

image: {
data: Buffer,
contentType: String
type: String,
default: "",
},


Expand Down
2 changes: 1 addition & 1 deletion server/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let UserSchema = Schema({

email: {
type: String,
lowercase: true,
unique: true,
lowercase: true,
required: true,
default: ""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports = function (req, res, next) {
const userId = req.user._id;
const activityId = req.params.activityId;
const groupNumber = parseInt(req.params.groupNumber, 10);
console.log("GN")
console.log(groupNumber)
console.log("GN")

Activity.findOneAndUpdate(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ const HttpStatus = require("http-status-codes");

const properties = ['name', 'image', 'email', 'surveyResponses'];

const images = [
"https://react.semantic-ui.com/assets/images/avatar/large/jenny.jpg",
"https://react.semantic-ui.com/assets/images/avatar/large/justen.jpg",
"https://react.semantic-ui.com/assets/images/avatar/large/stevie.jpg",
"https://react.semantic-ui.com/assets/images/avatar/large/veronika.jpg",
"https://semantic-ui.com/images/avatar/large/steve.jpg",
"https://semantic-ui.com/images/avatar2/large/kristy.png",
"https://semantic-ui.com/images/avatar2/large/matthew.png",
"https://semantic-ui.com/images/avatar2/large/molly.png",
"https://semantic-ui.com/images/avatar2/large/elyse.png",
"https://semantic-ui.com/images/avatar/large/daniel.jpg",
"https://semantic-ui.com/images/avatar/large/helen.jpg",

];

let randomBetween = (minVal, maxVal) => {
return Math.floor(Math.random() * (maxVal-minVal+1)) + minVal;
};

function pickImage () {
return images[randomBetween(0, images.length-1)];
};

function validateInput(req) {
let payload = req.body;
Expand Down Expand Up @@ -43,6 +65,9 @@ module.exports = function (req, res, next) {

const payload = req.body;
const activityId = req.params.activityId;

console.log(payload);
console.log(payload.surveyResponses);

// check if the activity is full. If so, then no other one can participate in
Activity.findOne({_id: activityId, isDeleted: false})
Expand All @@ -62,7 +87,7 @@ module.exports = function (req, res, next) {
_creator: activity._creator,
email: payload.email,
name: payload.name,
image: payload.image,
image: pickImage(),
surveyResponses: payload.surveyResponses,
});
newParticipant.save()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* Created by rui on 5/16/17.
*/
const Activity = require("../../../../models/").Activity;
const Participant = require("../../../../models/").Participant;
const ParticipantValidator = require("../../../../models").ParticipantValidator;
const ObjectIdIsValid = require("mongoose").Types.ObjectId.isValid;

const createErrorHandler = require("../../../utils").createErrorHandler;
const HttpStatus = require("http-status-codes");

const properties = ['name', 'image', 'email', 'surveyResponses'];

const images = [
"https://react.semantic-ui.com/assets/images/avatar/large/jenny.jpg",
"https://react.semantic-ui.com/assets/images/avatar/large/justen.jpg",
"https://react.semantic-ui.com/assets/images/avatar/large/stevie.jpg",
"https://react.semantic-ui.com/assets/images/avatar/large/veronika.jpg",
"https://semantic-ui.com/images/avatar/large/steve.jpg",
"https://semantic-ui.com/images/avatar2/large/kristy.png",
"https://semantic-ui.com/images/avatar2/large/matthew.png",
"https://semantic-ui.com/images/avatar2/large/molly.png",
"https://semantic-ui.com/images/avatar2/large/elyse.png",
"https://semantic-ui.com/images/avatar/large/daniel.jpg",
"https://semantic-ui.com/images/avatar/large/helen.jpg",

];

let randomBetween = (minVal, maxVal) => {
return Math.floor(Math.random() * (maxVal-minVal+1)) + minVal;
};

function pickImage () {
return images[randomBetween(0, images.length-1)];
};

function validateInput(req) {
let payload = req.body;
return validateParameters(req.params) && validateFormat(payload, properties)
&& ParticipantValidator(payload.name, payload.email, payload.image, payload.surveyResponses);
}


function validateParameters(prm) {
return prm.hasOwnProperty('activityId') && typeof prm.activityId === 'string'
&& ObjectIdIsValid(prm.activityId);
}


function validateFormat(payload, properties){
let res = true;
properties.forEach(function (property) {
res = res && payload.hasOwnProperty(property);
});
return res;
}


module.exports = function (req, res, next) {
if (!validateInput(req)) {
const errorMessage = 'please give valid activityID in URL and correct payload';
createErrorHandler(res, HttpStatus.BAD_REQUEST)(errorMessage);
return;
}

const payload = req.body;
const activityId = req.params.activityId;
<<<<<<< HEAD

console.log(payload);
console.log(payload.surveyResponses);
=======
>>>>>>> a165bb757d8a7aad48820d6f96d783d3fc4c9c50

// check if the activity is full. If so, then no other one can participate in
Activity.findOne({_id: activityId, isDeleted: false})
.exec()
.then(function (activity){
if (activity === null){
const errorMessage = "Cannot find activity has id: " + activityId + " in which to create new participant";
return createErrorHandler(res, HttpStatus.NOT_FOUND)(errorMessage);
}
if (activity.totalCapacity <= activity.currentCapacity){
const errorMessage = "The activity is full, no other one can participate in";
return createErrorHandler(res, HttpStatus.NOT_FOUND)(errorMessage);
}
// save a new participant
const newParticipant = new Participant({
_activity: activityId,
_creator: activity._creator,
email: payload.email,
name: payload.name,
image: pickImage(),
surveyResponses: payload.surveyResponses,
});
newParticipant.save()
.then(function(participant){

// update activity
activity.participants.push({_id: participant.id});
activity.lastModifiedTime = Date.now();
activity.currentCapacity ++;

activity.save().then(function(act){
return res.status(HttpStatus.CREATED).json({
participant: participant.getPublicFields()
})
}).catch(createErrorHandler(res, HttpStatus.INTERNAL_SERVER_ERROR));
})
.catch(createErrorHandler(res, HttpStatus.INTERNAL_SERVER_ERROR));


}).catch(createErrorHandler(res, HttpStatus.INTERNAL_SERVER_ERROR));

};
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ module.exports = function (req, res, next) {

return res.json({
participants: activity.participants,
lockedGroups: activity.lockedGroups,
totalCapacity: activity.totalCapacity,
groupCapacity: activity.groupCapacity,
})
})
.catch(createErrorHandler(res, HttpStatus.INTERNAL_SERVER_ERROR));
Expand Down
4 changes: 2 additions & 2 deletions server/routes/surveys/controllers/createSurveyController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ module.exports = function (req, res, next) {
createErrorHandler(res, HttpStatus.BAD_REQUEST)(errorMessage);
return;
}

const userId = req.user._id;
const payload = req.body;

const newSurvey = new Survey({
_creator: userId,
title: payload.title,
Expand Down
Loading

0 comments on commit d5d2056

Please sign in to comment.