vicinityManager/server/services/users/deleteUsers.js
/*
Delete == Remove relevant fields and change status to removed
Need to keep some fields for auditing purposes
*/
Delete == Remove relevant fields and change status to removed
Need to keep some fields for auditing purposes
Delete == Remove relevant fields and change status to removed Need to keep some fields for auditing purposes
function deleting(id, otherParams, callback){
  var cid;
  var obj = {
    avatar: "",
    occupation: "",
    location: "",
    status: "deleted",
    authentication: {},
    hasItems: [],
    hasContracts: [],
    cid: {}
  };
  userOp.findOne({_id: id}, {cid:1, hasItems:1, email:1}).populate('hasItems.id', 'cid oid')
  .then(function(response){
    var aux = response.toObject();
    var toDisable = [];
    cid = aux.cid;
    for(var i = 0; i < aux.hasItems.length; i++){
      toDisable.push(aux.hasItems[i].id);
    }
    disableUserItems(toDisable, otherParams.userMail, otherParams.userId)
    .then(function(response){ logger.debug('Disable items finished'); })
    .catch(function(err){ logger.debug('Disable items error: ' + err); });
    return userOp.update({_id: id}, { $set: obj });
  })
  .then(function(response){
    return audits.create(
      { kind: 'user', item: otherParams.userId , extid: otherParams.userMail },
      { kind: 'userAccount', item: cid.id, extid: cid.extid },
      { kind: 'user', extid: aux.email },
      12, null);
  })
  .then(function(response){ return userAccountOp.update({_id: cid.id}, {$pull: {accountOf: { id: id }}}); })
  .then(function(response){
    logger.audit({user: otherParams.userMail, action: 'deleteUser', item: id });
    callback(id, "Success");
  })
  .catch(function(error){
    logger.error({user: otherParams.userMail, action: 'deleteUser', item: id, message: JSON.stringify(error)});
    callback(id, "Error: " + error);
  });
}
function deleting ( id , otherParams , callback ) { var cid ; var obj = { avatar : "" , occupation : "" , location : "" , status : "deleted" , authentication : { } , hasItems : [ ] , hasContracts : [ ] , cid : { } } ; userOp . findOne ( { _id : id } , { cid : 1 , hasItems : 1 , email : 1 } ) . populate ( 'hasItems.id' , 'cid oid' ) . then ( function ( response ) { var aux = response . toObject ( ) ; var toDisable = [ ] ; cid = aux . cid ; for ( var i = 0 ; i < aux . hasItems . length ; i ++ ) { toDisable . push ( aux . hasItems [ i ] . id ) ; } disableUserItems ( toDisable , otherParams . userMail , otherParams . userId ) . then ( function ( response ) { logger . debug ( 'Disable items finished' ) ; } ) . catch ( function ( err ) { logger . debug ( 'Disable items error: ' + err ) ; } ) ; return userOp . update ( { _id : id } , { $set : obj } ) ; } ) . then ( function ( response ) { return audits . create ( { kind : 'user' , item : otherParams . userId , extid : otherParams . userMail } , { kind : 'userAccount' , item : cid . id , extid : cid . extid } , { kind : 'user' , extid : aux . email } , 12 , null ) ; } ) . then ( function ( response ) { return userAccountOp . update ( { _id : cid . id } , { $pull : { accountOf : { id : id } } } ) ; } ) . then ( function ( response ) { logger . audit ( { user : otherParams . userMail , action : 'deleteUser' , item : id } ) ; callback ( id , "Success" ) ; } ) . catch ( function ( error ) { logger . error ( { user : otherParams . userMail , action : 'deleteUser' , item : id , message : JSON . stringify ( error ) } ) ; callback ( id , "Error: " + error ) ; } ) ; }
Delete == Remove relevant fields and change status to removed
Need to keep some fields for auditing purposes
Delete == Remove relevant fields and change status to removed Need to keep some fields for auditing purposes
//logger.debug('START execution with value =', id);