lib/impl/dataTargets.js
function remove(connections, params, cb) {
  var failed = validate(params).has(CONSTANTS.DATA_TARGET_ID);

  if (failed) {
    return cb(buildErrorResponse({error: new Error("An ID Parameter Is Required To Remove A Data Target"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
  }

  if (!misc.checkId(params._id)) {
    return cb(buildErrorResponse({error: new Error("Invalid ID Paramter"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
  }

  async.waterfall([
    function findAssociatedForms(cb) {
      checkFormsUsingDataTarget(connections, params, cb);
    },
    function verifyNoFormsAssociated(updatedDataTarget, cb) {
      //If there is more than one form using this data target, then do not delete it.

      if (updatedDataTarget.forms.length > 0) {
        return cb(buildErrorResponse({
          error: new Error("Forms Are Associated With This Data Target. Please Disassociate Forms From This Data Target Before Deleting."),
          code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
        }));
      }

      return cb(undefined, updatedDataTarget);
    },
    function processResponse(updatedDataTarget, cb) {
      //Removing The Data Target
      var DataTarget = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_TARGET);

      DataTarget.remove({_id: updatedDataTarget._id}, function(err) {
        if (err) {
          return cb(buildErrorResponse({
            error: err,
            userDetail: "Unexpected Error When Removing A Data Target",
            code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
          }));
        }

        //Data Target Removed Successfully
        return cb();
      });
    }
  ], cb);

}
function remove(connections, params, cb) {
  var failed = validate(params).has(CONSTANTS.DATA_TARGET_ID);

  if (failed) {
    return cb(buildErrorResponse({error: new Error("An ID Parameter Is Required To Remove A Data Target"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
  }

  if (!misc.checkId(params._id)) {
    return cb(buildErrorResponse({error: new Error("Invalid ID Paramter"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
  }

  async.waterfall([
    function findAssociatedForms(cb) {
      checkFormsUsingDataTarget(connections, params, cb);
    },
    function verifyNoFormsAssociated(updatedDataTarget, cb) {
      //If there is more than one form using this data target, then do not delete it.

      if (updatedDataTarget.forms.length > 0) {
        return cb(buildErrorResponse({
          error: new Error("Forms Are Associated With This Data Target. Please Disassociate Forms From This Data Target Before Deleting."),
          code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
        }));
      }

      return cb(undefined, updatedDataTarget);
    },
    function processResponse(updatedDataTarget, cb) {
      //Removing The Data Target
      var DataTarget = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_TARGET);

      DataTarget.remove({_id: updatedDataTarget._id}, function(err) {
        if (err) {
          return cb(buildErrorResponse({
            error: err,
            userDetail: "Unexpected Error When Removing A Data Target",
            code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
          }));
        }

        //Data Target Removed Successfully
        return cb();
      });
    }
  ], cb);

}
function remove ( connections , params , cb ) { var failed = validate ( params ) . has ( CONSTANTS . DATA_TARGET_ID ) ; if ( failed ) { return cb ( buildErrorResponse ( { error : new Error ( "An ID Parameter Is Required To Remove A Data Target" ) , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } if ( ! misc . checkId ( params . _id ) ) { return cb ( buildErrorResponse ( { error : new Error ( "Invalid ID Paramter" ) , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } async . waterfall ( [ function findAssociatedForms ( cb ) { checkFormsUsingDataTarget ( connections , params , cb ) ; } , function verifyNoFormsAssociated ( updatedDataTarget , cb ) { //If there is more than one form using this data target, then do not delete it. if ( updatedDataTarget . forms . length > 0 ) { return cb ( buildErrorResponse ( { error : new Error ( "Forms Are Associated With This Data Target. Please Disassociate Forms From This Data Target Before Deleting." ) , code : ERROR_CODES . FH_FORMS_UNEXPECTED_ERROR } ) ) ; } return cb ( undefined , updatedDataTarget ) ; } , function processResponse ( updatedDataTarget , cb ) { //Removing The Data Target var DataTarget = models . get ( connections . mongooseConnection , models . MODELNAMES . DATA_TARGET ) ; DataTarget . remove ( { _id : updatedDataTarget . _id } , function ( err ) { if ( err ) { return cb ( buildErrorResponse ( { error : err , userDetail : "Unexpected Error When Removing A Data Target" , code : ERROR_CODES . FH_FORMS_UNEXPECTED_ERROR } ) ) ; } //Data Target Removed Successfully return cb ( ) ; } ) ; } ] , cb ) ; }
Removing A Data Target
@param connections
@param params
@param cb
Removing A Data Target