diff --git a/api/v1/controllers/index.js b/api/v1/controllers/index.js index b1759de..91b1574 100644 --- a/api/v1/controllers/index.js +++ b/api/v1/controllers/index.js @@ -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') -}; \ No newline at end of file +}; diff --git a/api/v1/services/RegistrationService.js b/api/v1/services/RegistrationService.js index 3681ea3..5150a98 100644 --- a/api/v1/services/RegistrationService.js +++ b/api/v1/services/RegistrationService.js @@ -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 () { @@ -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); }); }); @@ -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;