diff --git a/server/config/main.js b/server/config/main.js index 763421d..5b50a6d 100644 --- a/server/config/main.js +++ b/server/config/main.js @@ -8,5 +8,5 @@ module.exports = { 'secret': 'asdawldjal', databaseUrl: 'mongodb://teamdivider:CIS4222017@ds137101.mlab.com:37101/teamdivider', authenticationMiddleware: passport.authenticate('jwt', { session: false }), - SENDGRID_API_KEY: "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", + SENDGRID_API_KEY: process.env.SENDGRID_API_KEY, }; diff --git a/server/routes/activities/controllers/emailParticipantsForCertainActivityController.js b/server/routes/activities/controllers/emailParticipantsForCertainActivityController.js index e1e833c..8281675 100644 --- a/server/routes/activities/controllers/emailParticipantsForCertainActivityController.js +++ b/server/routes/activities/controllers/emailParticipantsForCertainActivityController.js @@ -4,9 +4,8 @@ const ObjectIdIsValid = require("mongoose").Types.ObjectId.isValid; const Activity = require("../../../models").Activity; -const sendgridAPIKey = require("../../../config/main").SENDGRID_API_KEY; -const sendgrid = require("sendgrid")(sendgridAPIKey); -const mailHelper = require('sendgrid').mail; +const sendGridAPIKey = require("../../../config/main").SENDGRID_API_KEY; + function groupParticipantsByGroupNumber (pars) { @@ -75,6 +74,13 @@ module.exports = function (req, res, next) { createErrorHandler(res, HttpStatus.BAD_REQUEST)(errorMessage); return; } + if (typeof sendGridAPIKey === 'undefined' || sendGridAPIKey === null){ + const errorMessage = 'Server terminal does not have the environment variable "SENDGRID_API_KEY". Please run the related bash script first.'; + createErrorHandler(res, HttpStatus.INTERNAL_SERVER_ERROR)(errorMessage); + return; + } + const sendGrid = require("sendgrid")(sendGridAPIKey); + const mailHelper = require('sendgrid').mail; Activity.findOne({_id: req.params.activityId, _creator: req.user._id, isDeleted: false}) .populate({ @@ -101,13 +107,13 @@ module.exports = function (req, res, next) { const content = new mailHelper.Content('text/html', generateHTMLText(member, group, activity)); const email = new mailHelper.Mail(from_email, subject, to_email, content); - const emailRequest = sendgrid.emptyRequest({ + const emailRequest = sendGrid.emptyRequest({ method: 'POST', path: '/v3/mail/send', body: email.toJSON() }); - sendgrid.API(emailRequest, function (error, response) { + sendGrid.API(emailRequest, function (error, response) { if (error !== null){ console.log(error); return; diff --git a/src/routes/Dashboard/components/ActivitiesView/components/ActivityCard/EditActivityInfoModal/EditActivityInfoModal.js b/src/routes/Dashboard/components/ActivitiesView/components/ActivityCard/EditActivityInfoModal/EditActivityInfoModal.js index 9c28021..4d0f82b 100644 --- a/src/routes/Dashboard/components/ActivitiesView/components/ActivityCard/EditActivityInfoModal/EditActivityInfoModal.js +++ b/src/routes/Dashboard/components/ActivitiesView/components/ActivityCard/EditActivityInfoModal/EditActivityInfoModal.js @@ -45,6 +45,12 @@ export default class EditActivityInfoModal extends React.Component { return; } + if (this.props.activityHolder.get('currentCapacity') >= + this.props.activityHolder.get('totalCapacity')) { + this.props.updateActivityFailedToEdit(true); + this.props.updateActivityEditError('TOTAL CAPACITY MUST NOT BE BIGGER THAN CURRENT CAPACITY'); + return; + } this.props.updateActivityFailedToEdit(false); this.props.updateActivityEditError(''); @@ -80,8 +86,8 @@ export default class EditActivityInfoModal extends React.Component { Cancel