var mongoose = require('mongoose');
import es6Promise from 'es6-promise';
mongoose.Promise = es6Promise.Promise;
const follow = (followerID, toFollowId, cb) => { //REVISE only update
User.update(
{ _id: toFollowId},
{$push: {usersFollowing: followerID}},
function(err){
if (err){
cb(true);
} else {
User.findByIdAndUpdate(
followerID,
{$push: {usersBeingFollowed: toFollowId}},
{safe: true, new: true},
function(err, model){
if (err){
cb(true);
} else {
cb(null, model);
}
}
)
}
}
)
}
const unfollow = (unfollowerId, toUnfollowId, cb) => { //REVISE only update
User.update(
{ _id: toUnfollowId},
{$pull: {usersFollowing: unfollowerId}}).then(
function(err){
if (err){
return cb(true);
} else {
User.findByIdAndUpdate(
unfollowerId,
{$pull: {usersBeingFollowed: toUnfollowId}},
{safe: true, new: true},
function(err, model){
if (err){
cb(true);
} else {
cb(null, model)
}
}
)
}
})
}
My follow function, which doesn't use a promise works fine. I tried editing my unfollow function to work as a promise, but it doesn't work. I haven't touched JS since ES5 but my promise understanding is that I just move the callback inside .then() and call it a day. What am I missing here?