lib/impl/dataSources/index.js
function deploy(connections, dataSource, cb) {

  async.waterfall([
    function validateParams(cb) {
      var dataSourceValidator = validate(dataSource);
      //The data source parameter should have an ID property.
      dataSourceValidator.has(CONSTANTS.DATA_SOURCE_ID, function(err) {
        if (err) {
          return cb(buildErrorResponse({error: new Error("An ID Parameter Is Required To Deploy A Data Source"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
        }

        cb(undefined, dataSource);
      });
    },
    function findDataSource(dataSource, cb) {
      var query = {

      };

      //Searching By ID.
      query[CONSTANTS.DATA_SOURCE_ID] = dataSource[CONSTANTS.DATA_SOURCE_ID];

      //Looking up a full data source document as we are updating
      lookUpDataSources(connections, {
        query: query,
        lean: false
      }, function(err, dataSources) {
        if (err) {
          return cb(buildErrorResponse({
            error: err,
            userDetail: "Unexpected Error When Searching For A Data Source",
            code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
          }));
        }

        //If no data sources found create, otherwise update.
        if (dataSources.length === 0) {
          connections.deploy = true;
          create(connections, dataSource, cb);
        } else {
          update(connections, dataSource, cb);
        }
      });
    }
  ], cb);
}
function deploy(connections, dataSource, cb) {

  async.waterfall([
    function validateParams(cb) {
      var dataSourceValidator = validate(dataSource);
      //The data source parameter should have an ID property.
      dataSourceValidator.has(CONSTANTS.DATA_SOURCE_ID, function(err) {
        if (err) {
          return cb(buildErrorResponse({error: new Error("An ID Parameter Is Required To Deploy A Data Source"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
        }

        cb(undefined, dataSource);
      });
    },
    function findDataSource(dataSource, cb) {
      var query = {

      };

      //Searching By ID.
      query[CONSTANTS.DATA_SOURCE_ID] = dataSource[CONSTANTS.DATA_SOURCE_ID];

      //Looking up a full data source document as we are updating
      lookUpDataSources(connections, {
        query: query,
        lean: false
      }, function(err, dataSources) {
        if (err) {
          return cb(buildErrorResponse({
            error: err,
            userDetail: "Unexpected Error When Searching For A Data Source",
            code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
          }));
        }

        //If no data sources found create, otherwise update.
        if (dataSources.length === 0) {
          connections.deploy = true;
          create(connections, dataSource, cb);
        } else {
          update(connections, dataSource, cb);
        }
      });
    }
  ], cb);
}
function deploy ( connections , dataSource , cb ) { async . waterfall ( [ function validateParams ( cb ) { var dataSourceValidator = validate ( dataSource ) ; //The data source parameter should have an ID property. dataSourceValidator . has ( CONSTANTS . DATA_SOURCE_ID , function ( err ) { if ( err ) { return cb ( buildErrorResponse ( { error : new Error ( "An ID Parameter Is Required To Deploy A Data Source" ) , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } cb ( undefined , dataSource ) ; } ) ; } , function findDataSource ( dataSource , cb ) { var query = { } ; //Searching By ID. query [ CONSTANTS . DATA_SOURCE_ID ] = dataSource [ CONSTANTS . DATA_SOURCE_ID ] ; //Looking up a full data source document as we are updating lookUpDataSources ( connections , { query : query , lean : false } , function ( err , dataSources ) { if ( err ) { return cb ( buildErrorResponse ( { error : err , userDetail : "Unexpected Error When Searching For A Data Source" , code : ERROR_CODES . FH_FORMS_UNEXPECTED_ERROR } ) ) ; } //If no data sources found create, otherwise update. if ( dataSources . length === 0 ) { connections . deploy = true ; create ( connections , dataSource , cb ) ; } else { update ( connections , dataSource , cb ) ; } } ) ; } ] , cb ) ; }
Deploying A Data Source. Check If It Exists First, then update, if not create it.
Deploying A Data Source . Check If It Exists First then update if not create it .