diff --git a/common/models/organizer.js b/common/models/organizer.js index 59b5717..0e6400c 100644 --- a/common/models/organizer.js +++ b/common/models/organizer.js @@ -3,14 +3,13 @@ const { sendEmailToNewAdmin } = require('../../server/utils/sendGridEmailer'); module.exports = function(Organizer) { - Organizer.afterRemote('create', function (ctx, modelInstance, next) { - const username = ctx.result.username; - const email = ctx.result.email; - sendEmailToNewAdmin(username, email) + Organizer.afterRemote('create', function (ctx, modelInstance, next) { + const username = ctx.result.username; + const email = ctx.result.email; + sendEmailToNewAdmin(username, email) .then(() => next()) .catch(err => { - next(new Error(err.message)); - }) - }); - + next(new Error(err.message)); + }); + }); }; diff --git a/server/utils/formatTalkForEmail.js b/server/utils/formatTalkForEmail.js index 4de3a38..dddc5d3 100644 --- a/server/utils/formatTalkForEmail.js +++ b/server/utils/formatTalkForEmail.js @@ -14,7 +14,7 @@ function formatTalkForEmail(speakerId, eventId) { .then(speaker => { const speakerName = speaker.speakerName; const speakerEmail = speaker.speakerEmail - Event.findById(eventId) + return Event.findById(eventId) .then(selectedEvent => { const meetupTitle = selectedEvent.name; const meetupDate = selectedEvent.date; diff --git a/server/utils/talkSubmit.js b/server/utils/talkSubmit.js index 105b8db..3b619a2 100644 --- a/server/utils/talkSubmit.js +++ b/server/utils/talkSubmit.js @@ -2,32 +2,30 @@ const app = require('../server'); const { getMeetups } = require('./getMeetups'); function talkSubmit(speakerInfo, talkInfo, date) { - return new Promise((resolve, reject) => { - const { Talk, Speaker, Event } = app.models; - Speaker.create(speakerInfo) - .then(response => { - let speakerId = response.id - getMeetups() - .then(meetups => { - const index = meetups.findIndex((item) => item.date == date); - let name = meetups[index].name; - let details = meetups[index].description; - let meetupId = meetups[index].meetupId; - if (index === -1 ) - return reject(new Error('NO meetup with that date found!')); - Event.findOrCreate({date, name, details, meetupId}) - .then(event => { - let eventId = event[0].id - Talk.create( { ...talkInfo, speakerId, eventId}) - .then(talk => resolve(talk)) - .catch(err => console.log(err)) - }) - .catch(err => reject(err)) - }) - .catch(err => reject(err)) + const { Talk, Speaker, Event } = app.models; + return getMeetups() + .then(meetups => { + const index = meetups.findIndex((item) => item.date == date); + let name = meetups[index].name; + let details = meetups[index].description; + let meetupId = meetups[index].meetupId; + if (index === -1) + return reject(new Error('NO meetup with that date found!')); + return Promise.all([ + Event.findOrCreate({ + date, name, details, + meetupId + }), + Speaker.create(speakerInfo)]) + }) + .then(([event, speaker]) => { + let eventId = event[0].id + let speakerId = speaker.id + return Talk.create({ + ...talkInfo, + speakerId, eventId }) - .catch(err => reject(err)) - }) + }) } module.exports = { talkSubmit }; diff --git a/src/components/Talks/Talks.jsx b/src/components/Talks/Talks.jsx index 5ce6455..462d339 100644 --- a/src/components/Talks/Talks.jsx +++ b/src/components/Talks/Talks.jsx @@ -18,7 +18,7 @@ const EditOptions = ({ talkId, handleSelect, name, children }) => { return (
- {children} @@ -38,16 +38,12 @@ const ShowMore = ({ topic, description, adminNotes, talkId, toggleShowMoreFuncti
- +