Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Merge pull request #71 from HackIllinois/fix/attendees
Browse files Browse the repository at this point in the history
Fix/attendees
  • Loading branch information
nmagerko authored Feb 5, 2017
2 parents eb7360f + 2313deb commit 537a98d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/v1/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
PermissionController: require('./PermissionController.js'),
ProjectController: require('./ProjectController.js'),
HealthController: require('./HealthController.js'),
RSVPController: require('./RSVPController.js')
RSVPController: require('./RSVPController.js'),
StatsController: require('./StatsController.js')
};
};
8 changes: 5 additions & 3 deletions api/v1/services/RegistrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ function _extractRelatedObjects(model, fkName, related) {
/**
* Removes unwanted objects and updates desired objects
* @param {Model} model the model with which the ideas are associated
* @param {String} parentKey the foreign key name for the associated model
* @param {Object} adjustments the resolved result of #_extractRelatedObjects
* @param {Transaction} t a pending transaction
* @return {Promise<>} a promise indicating all changes have been added to the transaction
*/
function _adjustRelatedObjects(model, adjustments, t) {
function _adjustRelatedObjects(model, parentKey, adjustments, t) {
var relatedPromises = [];

_.forIn(adjustments, function (adjustment, relatedName) {
var promise = model.related(relatedName)
.query().transacting(t)
.whereNotIn('id', adjustment.updatedIds)
.where(parentKey, model.get('id'))
.delete()
.catch(Model.NoRowsDeletedError, function () { return null; })
.then(function () {
Expand Down Expand Up @@ -290,7 +292,7 @@ module.exports.updateMentor = function (mentor, attributes) {
})
.then(function (adjustments){
return Mentor.transaction(function (t) {
return _adjustMentorIdeas(mentor, adjustments, t).then(function () {
return _adjustMentorIdeas(mentor, "mentor_id", adjustments, t).then(function () {
return _saveWithRelated(mentor, { 'ideas': adjustments.ideas.new }, t);
});
});
Expand Down Expand Up @@ -426,7 +428,7 @@ module.exports.updateAttendee = function (attendee, attributes) {
})
.then(function (adjustments) {
return Attendee.transaction(function (t) {
return _adjustRelatedObjects(attendee, adjustments, t)
return _adjustRelatedObjects(attendee, "attendee_id", adjustments, t)
.then(function () {
var newRelated = _.mapValues(adjustments, function (adjustment, adjustments) {
return adjustment.new;
Expand Down

0 comments on commit 537a98d

Please sign in to comment.