vicinityManager/server/services/organisations/configuration.js
/*
Removes organisation and everything under:
Users, nodes, items
*/
Removes organisation and everything under:
Users, nodes, items
Removes organisation and everything under : Users nodes items
function remove(cid, mail, callback) {
  var deletingResults = {};
  logger.debug('Removing organisation... ' + cid);
  companyAccountOp.findOne({ _id: cid },
    function(err, companyData){
      if (err) {
        callback(true, err);
      } else {
        var companyDataParsed = companyData.toObject();
        var users = [];
        getOids(companyDataParsed.accountOf, users, 'id');
        delUser.deleteAllUsers(users, mail)
        .then(function(response){
          deletingResults.users = response;
          var nodes = [];
          getOids(companyDataParsed.hasNodes, nodes, 'extid');
          return myNode.deleteNode(nodes, mail);
        })
        .then(function(response){
          deletingResults.nodes = response;
          companyData.location = "";
          companyData.hasNotifications = [];
          companyData.hasNodes = [];
          companyData.knows = [];
          companyData.knowsRequestsTo = [];
          companyData.knowsRequestsFrom = [];
          companyData.avatar = "";
          companyData.status = "deleted";
          return companyData.save();
        })
        .then(function(response){
          deletingResults.organisation = {cid: cid, result: 'Success'};
          logger.audit({user: mail, action: 'deleteOrganisation', item: cid });
          logger.debug('Success deleting organisation!!!');
          logger.debug({result: deletingResults});
          callback(false, deletingResults);
        })
        .catch(function(err){
          logger.error({user: mail, action: 'deleteOrganisation', item: cid, message: err});
          callback(true, err);
        });
      }
    }
  );
}
function remove ( cid , mail , callback ) { var deletingResults = { } ; logger . debug ( 'Removing organisation... ' + cid ) ; companyAccountOp . findOne ( { _id : cid } , function ( err , companyData ) { if ( err ) { callback ( true , err ) ; } else { var companyDataParsed = companyData . toObject ( ) ; var users = [ ] ; getOids ( companyDataParsed . accountOf , users , 'id' ) ; delUser . deleteAllUsers ( users , mail ) . then ( function ( response ) { deletingResults . users = response ; var nodes = [ ] ; getOids ( companyDataParsed . hasNodes , nodes , 'extid' ) ; return myNode . deleteNode ( nodes , mail ) ; } ) . then ( function ( response ) { deletingResults . nodes = response ; companyData . location = "" ; companyData . hasNotifications = [ ] ; companyData . hasNodes = [ ] ; companyData . knows = [ ] ; companyData . knowsRequestsTo = [ ] ; companyData . knowsRequestsFrom = [ ] ; companyData . avatar = "" ; companyData . status = "deleted" ; return companyData . save ( ) ; } ) . then ( function ( response ) { deletingResults . organisation = { cid : cid , result : 'Success' } ; logger . audit ( { user : mail , action : 'deleteOrganisation' , item : cid } ) ; logger . debug ( 'Success deleting organisation!!!' ) ; logger . debug ( { result : deletingResults } ) ; callback ( false , deletingResults ) ; } ) . catch ( function ( err ) { logger . error ( { user : mail , action : 'deleteOrganisation' , item : cid , message : err } ) ; callback ( true , err ) ; } ) ; } } ) ; }
Removes organisation and everything under:
Users, nodes, items
Removes organisation and everything under : Users nodes items
// TODO uncomment/comment next 8 lines to test or have real behaviour // .then(function(response){ // TODO Decide if necessary - Nobody to log the audit to //   return audits.putAuditInt( //     cid, //     { orgOrigin: companyData.cid, // extid //       user: mail, //       eventType: 2 } //   ); // })