From 21135f61b23a13916403422c658602c3ee66817e Mon Sep 17 00:00:00 2001 From: Helen Li Date: Fri, 4 Jun 2021 18:23:11 -0400 Subject: [PATCH] removing student from class should also remove them from specific nonglobal section --- models/utils.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/models/utils.js b/models/utils.js index b5ed281..41ba2a3 100644 --- a/models/utils.js +++ b/models/utils.js @@ -142,9 +142,22 @@ module.exports = function(models){ removeStudent: function(classId, userId){ return Class.findByPk(classId, {include:[{association: 'GlobalSection'}]}) .then((nb_class) => - User.findByPk(userId).then((user) => + User.findByPk(userId).then((user) => { nb_class.GlobalSection.removeMemberStudent(user) - ) + // remove student from existing non-global section + Section.findOne({ where: {class_id: classId, is_global: false}, + include: [{ + model: models.User, + as: 'MemberStudents', + where: { id: userId }, // filter to find a section with this student + }] + }) + .then(function (section) { + if (section) { + section.removeMemberStudent(user); + } + }) + }) ); }, createAnnotation: function(location, head, instructors, sessionUserId) {