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

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

  if (!misc.checkId(params[CONSTANTS.DATA_SOURCE_ID])) {
    return cb(buildErrorResponse({error: new Error("Invalid ID Parameter"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
  }
  var DataSource = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_SOURCE);

  async.waterfall([
    function findAssociatedForms(cb) {
      checkFormsUsingDataSource(connections, params, cb);
    },
    function verifyNoFormsAssociated(updatedDataSource, cb) {
      //If there are any forms using this data source, then do not delete it.
      logger.debug("Remove Data Source ", {updatedDataSource: updatedDataSource});

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

      return cb(undefined, updatedDataSource);
    },
    function processResponse(updatedDataSource, cb) {
      //Removing The Data Source

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

        //Data Source Removed Successfully
        return cb(undefined, updatedDataSource);
      });
    },
    function removeAduditLogs(updatedDataSource, cb) {
      DataSource.clearAuditLogs(updatedDataSource._id, cb);
    }
  ], cb);
}
function remove(connections, params, cb) {
  var failed = validate(params).has(CONSTANTS.DATA_SOURCE_ID);

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

  if (!misc.checkId(params[CONSTANTS.DATA_SOURCE_ID])) {
    return cb(buildErrorResponse({error: new Error("Invalid ID Parameter"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
  }
  var DataSource = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_SOURCE);

  async.waterfall([
    function findAssociatedForms(cb) {
      checkFormsUsingDataSource(connections, params, cb);
    },
    function verifyNoFormsAssociated(updatedDataSource, cb) {
      //If there are any forms using this data source, then do not delete it.
      logger.debug("Remove Data Source ", {updatedDataSource: updatedDataSource});

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

      return cb(undefined, updatedDataSource);
    },
    function processResponse(updatedDataSource, cb) {
      //Removing The Data Source

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

        //Data Source Removed Successfully
        return cb(undefined, updatedDataSource);
      });
    },
    function removeAduditLogs(updatedDataSource, cb) {
      DataSource.clearAuditLogs(updatedDataSource._id, cb);
    }
  ], cb);
}
function remove ( connections , params , cb ) { var failed = validate ( params ) . has ( CONSTANTS . DATA_SOURCE_ID ) ; if ( failed ) { return cb ( buildErrorResponse ( { error : new Error ( "An ID Parameter Is Required To Remove A Data Source" ) , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } if ( ! misc . checkId ( params [ CONSTANTS . DATA_SOURCE_ID ] ) ) { return cb ( buildErrorResponse ( { error : new Error ( "Invalid ID Parameter" ) , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } var DataSource = models . get ( connections . mongooseConnection , models . MODELNAMES . DATA_SOURCE ) ; async . waterfall ( [ function findAssociatedForms ( cb ) { checkFormsUsingDataSource ( connections , params , cb ) ; } , function verifyNoFormsAssociated ( updatedDataSource , cb ) { //If there are any forms using this data source, then do not delete it. logger . debug ( "Remove Data Source " , { updatedDataSource : updatedDataSource } ) ; if ( updatedDataSource . forms . length > 0 ) { return cb ( buildErrorResponse ( { error : new Error ( "Forms Are Associated With This Data Source. Please Disassociate Forms From This Data Source Before Deleting." ) , code : ERROR_CODES . FH_FORMS_UNEXPECTED_ERROR } ) ) ; } return cb ( undefined , updatedDataSource ) ; } , function processResponse ( updatedDataSource , cb ) { //Removing The Data Source DataSource . remove ( { _id : updatedDataSource . _id } , function ( err ) { if ( err ) { return cb ( buildErrorResponse ( { error : err , userDetail : "Unexpected Error When Removing A Data Source" , code : ERROR_CODES . FH_FORMS_UNEXPECTED_ERROR } ) ) ; } //Data Source Removed Successfully return cb ( undefined , updatedDataSource ) ; } ) ; } , function removeAduditLogs ( updatedDataSource , cb ) { DataSource . clearAuditLogs ( updatedDataSource . _id , cb ) ; } ] , cb ) ; }
Removing A Data Source
@param connections
@param params
@param cb
Removing A Data Source