vicinityManager/server/services/items/deleteItems.js
/*
Delete == Remove relevant fields and change status to removed
Make sure that agent is deleted or break connection with removed object
*/
Delete == Remove relevant fields and change status to removed
Make sure that agent is deleted or break connection with removed object
Delete == Remove relevant fields and change status to removed Make sure that agent is deleted or break connection with removed object
function deleting(oid, otherParams, callback){
  logger.debug('START execution with value =', oid);
  var obj = {
    info: {},
    avatar: "",
    accessLevel: 0,
    status: 'deleted',
    cid: [],
    adid: [],
    hasContracts: []
  };
  itemOp.findOne({oid:oid}, {avatar:0},
    function(err,data){
      if(err){
        logger.debug("Something went wrong: " + err);
        callback(oid, "error mongo" + err);
      }else if(!data){
        logger.debug("Object does not exist");
        callback(oid, "Object does not exist");
      }else{
        var cid = data.cid;
        var id = data._id;
        itemOp.update({oid:oid}, {$set: obj})
        .then(function(response){ return nodeOp.update({_id: data.adid.id}, {$pull: {hasItems: { extid : oid }}}); })
        .then(function(response){ return userOp.update({_id: data.uid.id}, {$pull: {hasItems: { extid : oid }}}); })
        .then(function(response){ return semanticRepo.callSemanticRepo({}, "td/remove/" + oid, 'DELETE'); })
        .then(function(response){
          return audits.create(
            { kind: 'user', item: data.uid.id, extid: data.uid.extid },
            { kind: 'userAccount', item: data.cid.id, extid: data.cid.extid },
            { kind: 'item', item: data._id, extid: data.oid, name: data.name },
            42, null);
        })
        .then(function(response){ return commServer.callCommServer({}, 'users/' + oid, 'DELETE'); })
        .then(function(ans){
          logger.audit({user: otherParams.userMail, action: 'deleteItem', item: oid });
          callback(oid, "Success");})
        .catch(function(err){
          if(err.statusCode !== 404){
            logger.error({user: otherParams.userMail, action: 'deleteItem', item: oid, message: err});
            callback(oid, 'Error: ' + err);
          } else {
            logger.warn({user: otherParams.userMail, action: 'deleteItem', item: oid, message: 'Object did not exist in comm server' });
            callback(oid, "Success");
          }
        });
      }
    });
  }
function deleting ( oid , otherParams , callback ) { logger . debug ( 'START execution with value =' , oid ) ; var obj = { info : { } , avatar : "" , accessLevel : 0 , status : 'deleted' , cid : [ ] , adid : [ ] , hasContracts : [ ] } ; itemOp . findOne ( { oid : oid } , { avatar : 0 } , function ( err , data ) { if ( err ) { logger . debug ( "Something went wrong: " + err ) ; callback ( oid , "error mongo" + err ) ; } else if ( ! data ) { logger . debug ( "Object does not exist" ) ; callback ( oid , "Object does not exist" ) ; } else { var cid = data . cid ; var id = data . _id ; itemOp . update ( { oid : oid } , { $set : obj } ) . then ( function ( response ) { return nodeOp . update ( { _id : data . adid . id } , { $pull : { hasItems : { extid : oid } } } ) ; } ) . then ( function ( response ) { return userOp . update ( { _id : data . uid . id } , { $pull : { hasItems : { extid : oid } } } ) ; } ) . then ( function ( response ) { return semanticRepo . callSemanticRepo ( { } , "td/remove/" + oid , 'DELETE' ) ; } ) . then ( function ( response ) { return audits . create ( { kind : 'user' , item : data . uid . id , extid : data . uid . extid } , { kind : 'userAccount' , item : data . cid . id , extid : data . cid . extid } , { kind : 'item' , item : data . _id , extid : data . oid , name : data . name } , 42 , null ) ; } ) . then ( function ( response ) { return commServer . callCommServer ( { } , 'users/' + oid , 'DELETE' ) ; } ) . then ( function ( ans ) { logger . audit ( { user : otherParams . userMail , action : 'deleteItem' , item : oid } ) ; callback ( oid , "Success" ) ; } ) . catch ( function ( err ) { if ( err . statusCode !== 404 ) { logger . error ( { user : otherParams . userMail , action : 'deleteItem' , item : oid , message : err } ) ; callback ( oid , 'Error: ' + err ) ; } else { logger . warn ( { user : otherParams . userMail , action : 'deleteItem' , item : oid , message : 'Object did not exist in comm server' } ) ; callback ( oid , "Success" ) ; } } ) ; } } ) ; }
Delete == Remove relevant fields and change status to removed
Make sure that agent is deleted or break connection with removed object
Delete == Remove relevant fields and change status to removed Make sure that agent is deleted or break connection with removed object