Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions routes/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ module.exports = function(app) {
var auth_token = req.get('Authorization');
jwt.verify(auth_token, app.get('superSecret'), function(err, userId) {
if (err) {
console.log(err);
res.sendStatus(500);
console.log('Error verifying auth token:', err);
res.status(401).send(err);
}
User.findById(userId, function(error, user) {
if (error) {
console.log(error);
res.sendStatus(500);
console.log('Error finding user by ID:', error);
res.status(500).send(error);
}
eventServices.createEvent(req.body, user.tier, function(createErr, event) {
if (createErr) {
console.log(createErr);
res.sendStatus(500);
console.log('Error creating event:', createErr);
res.status(500).send(createErr);
} else {
console.log('New event created: ' + event);
res.json({
Expand All @@ -39,18 +39,18 @@ module.exports = function(app) {
var auth_token = req.get('Authorization');
jwt.verify(auth_token, app.get('superSecret'), function(err, userId) {
if (err) {
console.log(err);
res.sendStatus(500);
console.log('Error verifying auth token:', err);
res.status(401).send(err);
}
User.findById(userId, function(error, user) {
if (error) {
console.log(error);
res.sendStatus(500);
console.log('Error finding user by ID:', error);
res.status(500).send(error);
}
eventServices.findAllEventsInTier(user.tier, function(err, events) {
if (err) {
console.error(err);
res.sendStatus(500);
eventServices.findAllEventsInTier(user.tier, function(errEvents, events) {
if (errEvents) {
console.error('Error finding all events in tier:', errEvents);
res.status(500).send(errEvents);
} else {
console.log(events);
res.json({
Expand All @@ -66,7 +66,7 @@ module.exports = function(app) {
app.post('/events/:id/rsvp', function(req, res, next) {
var auth_token = req.get('Authorization');
jwt.verify(auth_token, app.get('superSecret'), function(error, userId) {
if (error) res.status(500).send("User not logged in: " + error);
if (error) res.status(401).send("User not logged in: " + error);
eventServices.rsvpToEvent(req.params.id, req.body.rsvp, userId, function(err, evnt) {
if (err) res.status(500).send("Could not rsvp to event: " + err);

Expand All @@ -84,8 +84,8 @@ module.exports = function(app) {
jwt.verify(auth_token, app.get('superSecret'), function(error, userId) {
eventServices.findOneEvent(req.params.id, function(err, evnt) {
if (err) {
console.log(err);
res.sendStatus(500);
console.log('Error finding one event:', err);
res.status(500).send(err);
} else {

var expandUser = function(userId, cb) {
Expand Down Expand Up @@ -120,8 +120,8 @@ module.exports = function(app) {

eventServices.findAllEvents(function(err, events) {
if (err) {
console.log(err);
res.sendStatus(500);
console.log('Error finding all events:', err);
res.status(500).send(err);
} else {
// not logging here since data might be massive

Expand All @@ -137,8 +137,8 @@ module.exports = function(app) {

eventServices.findAllEventsInTier(function(err, tier, events) {
if (err) {
console.log(err);
res.sendStatus(500);
console.log('Error finding all events in tier:', err);
res.status(500).send(err);
} else {
res.json({
events: events
Expand Down
33 changes: 18 additions & 15 deletions routes/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ var postServices = require('../services/postServices');

module.exports = function(app) {

// Expects form data in the form of:
// {
// authorId: String,
// content: String
// }
/* Expects form data in the form of:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dat style tho

{
authorId: String,
content: String
}
*/
app.post('/posts/create', function(req, res, next) {
var auth_token = req.get('Authorization');
jwt.verify(auth_token, app.get('superSecret'), function(error, userId) {
User.findById(userId, function(error, user) {
if (error) {
res.status(500).send(error);
if (error) {
console.log('Error finding by ID:', error);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we have some funky spacing going on here

res.status(500).send(error);
} else if (user) {
req.body.authorId = user._id;
postServices.createPost(req.body, user.tier, function(err, post) {
if (err) {
console.log(err);
res.sendStatus(500);
console.log('Error creating post:', err);
res.status(500).send(err);
} else {
User.findById(post.authorId, function(error, author) {
User.findById(post.authorId, function(errorById, author) {
var newPost = post.toObject();
newPost.displayName = author.firstName + " " + author.lastName;
res.json({
Expand All @@ -46,17 +48,18 @@ module.exports = function(app) {
var lastTimestamp = req.query.lastTimestamp;
jwt.verify(auth_token, app.get('superSecret'), function(err, userId) {
if (err) {
console.log(err);
res.sendStatus(500);
console.log('Error verifying auth token:', err);
res.status(401).send(err);
} else {
User.findById(userId, function(error, user) {
if (error) {
console.log(error);
res.sendStatus(500);
console.log('Error finding by ID:', error);
res.status(500).send(error);
}
postServices.findAllPosts(user.tier, limit, lastTimestamp, function(err, posts) {
if (err) {
res.status(500).send(err);
console.log('Error finding all posts:', err);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like some funky spacing going on here

res.status(500).send(err);
return;
}

Expand Down