Skip to content
This repository has been archived by the owner on Jul 16, 2018. It is now read-only.

Commit

Permalink
REDO Bug 914904 Protect against SQL errors... 07ec508
Browse files Browse the repository at this point in the history
  • Loading branch information
k88hudson committed Sep 18, 2013
1 parent 3ee7177 commit ecec594
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lib/events/controllers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ module.exports = function(init) {
var allowed = util.sans(SAFE_FIELDS, ['id', 'featured', 'picture']).concat('organizer');

Event.create(event, allowed).success(picture_handler(picture, function (event) {
if (err)
return res.reply(500, { error: err });

geocode_filler(event);
res.reply(201, 'Event created', { event: event_output_filter(event) },
{ location: event.uri() });
Expand Down Expand Up @@ -103,6 +106,8 @@ module.exports = function(init) {
allowed.push('featured');

event.updateAttributes(changes, allowed).success(picture_handler(picture, function (event) {
if (err)
return res.reply(500, { error: err });
geocode_filler(event);
res.reply(200, 'Event modified', { event: event_output_filter(event) })
})).error(function(err) {
Expand All @@ -118,6 +123,10 @@ module.exports = function(init) {
if (picture)
s3.delete(picture);
res.reply(200, 'Event deleted');
}).error(function (err) {
res.reply( 500, {
error: err
});
});
}, true);
},
Expand Down Expand Up @@ -175,9 +184,15 @@ module.exports = function(init) {
s3.put(picture.data, picture.type, function(f) {
if (event.picture)
s3.delete(event.picture);
event.updateAttributes({ picture: s3.url(f) }).success(cb)
event.updateAttributes({
picture: s3.url(f)
}).success(function (event) {
cb(null, event);
}).error(function( err) {
cb(err);
});
})
else cb(event);
else cb(null, event);
}
}

Expand Down Expand Up @@ -367,7 +382,10 @@ module.exports = function(init) {
var page = Math.abs(parseInt(req.query._page) || 0),
limit = Math.abs(parseInt(req.query._limit) || PAGE_SIZE);

Event.findAll({ offset: page * limit, limit: limit }).success(function(events) {
Event.findAll({
offset: page * limit,
limit: limit
}).success(function(events) {
var count = events.length;

_reply_events({
Expand All @@ -378,9 +396,17 @@ module.exports = function(init) {
offset: page * limit,
events: events
}, isAdmin);
}).error(function (err) {
res.reply(500, {
error: err
});
});
} else Event.all().success(function(events) {
_reply_events({ events: events }, isAdmin);
}).error(function (err) {
res.reply(500, {
error: err
});
});
}
if (req.session.username || requireAdmin)
Expand Down

0 comments on commit ecec594

Please sign in to comment.