src/lib/db.js
function composeAddRemoveGroupMember({ action="add", roles="members" }) {
  /**
   * Add/Remove user from group
   *
   * @param {String} username
   * @param {String} groupname
   * @param {Function} done - done(err)
   */
   return function(username, groupname, done) {
     return getGroup(groupname, function(getGroupErr, group) {
       if (getGroupErr) {
         return done(getGroupErr);
       }

       if (!group) {
         return done(new Error(`group '${groupname}' not found`));
       }

       return getUser(username, function(getUserErr, user) {
         if (getUserErr) {
           return done(getUserErr);
         }

         if (!user) {
           return done(new Error(`user '${username}' not found`));
         }

         group[roles][action](user.id);
         return group.save(done);
       });
     });
   };
}
function composeAddRemoveGroupMember({ action="add", roles="members" }) {
  /**
   * Add/Remove user from group
   *
   * @param {String} username
   * @param {String} groupname
   * @param {Function} done - done(err)
   */
   return function(username, groupname, done) {
     return getGroup(groupname, function(getGroupErr, group) {
       if (getGroupErr) {
         return done(getGroupErr);
       }

       if (!group) {
         return done(new Error(`group '${groupname}' not found`));
       }

       return getUser(username, function(getUserErr, user) {
         if (getUserErr) {
           return done(getUserErr);
         }

         if (!user) {
           return done(new Error(`user '${username}' not found`));
         }

         group[roles][action](user.id);
         return group.save(done);
       });
     });
   };
}
function composeAddRemoveGroupMember ( { action = "add" , roles = "members" } ) { /**
   * Add/Remove user from group
   *
   * @param {String} username
   * @param {String} groupname
   * @param {Function} done - done(err)
   */ return function ( username , groupname , done ) { return getGroup ( groupname , function ( getGroupErr , group ) { if ( getGroupErr ) { return done ( getGroupErr ) ; } if ( ! group ) { return done ( new Error ( ` ${ groupname } ` ) ) ; } return getUser ( username , function ( getUserErr , user ) { if ( getUserErr ) { return done ( getUserErr ) ; } if ( ! user ) { return done ( new Error ( ` ${ username } ` ) ) ; } group [ roles ] [ action ] ( user . id ) ; return group . save ( done ) ; } ) ; } ) ; } ; }
Compose function for removing or adding user to group

@param {Boolean} [action="add"]
Compose function for removing or adding user to group