I'm new to promises and I feel like this should be a pretty simple thing to do.
I would like the below code to stop at the first then
if the variable returns true:
if (groupCodes.length === 1) {
// Get all does not populate the group object so it will just be the identifier as we require
var groupIdentifier = groupCodes[0].group;
GroupMember
.nestedCreate({ groupId: groupIdentifier, type: groupCodes[0].type }, { })
.$promise
.then(function (group) {
var isUserAlreadyInGroup = _.includes(group, user._id);
if (isUserAlreadyInGroup) {
// If this variable returns true I would like to preent the below then function from running
notify.info('You have already joined ' + scope.groupCode);
}
})
.then(function () {
// Now that we have joined the group, we have permission
// to access the group data.
return Group
.getById({ groupId: groupIdentifier })
.$promise;
})
}