lib/impl/dataTargets.js
function create(connections, dataTarget, cb) {
  async.waterfall([
    function validateParams(cb) {
      validate(dataTarget).hasno(CONSTANTS.DATA_TARGET_ID, function(err) {
        if (err) {
          return cb(buildErrorResponse({error: new Error("Data Target ID Should Not Be Included When Creating A Data Target"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
        }
      });

      cb(undefined, dataTarget);
    },
    function createDataTarget(dataTargetJSON, cb) {
      dataTargetJSON = sanitiseJSON(dataTargetJSON);

      var DataTarget = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_TARGET);
      var newDataTarget = new DataTarget(dataTargetJSON);

      newDataTarget.save(function(err) {
        if (err) {
          return cb(buildErrorResponse({
            error: err,
            userDetail: "Invalid Data Target Creation Data.",
            systemDetail: err.errors,
            code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS
          }));
        }

        return cb(undefined, newDataTarget.toJSON());
      });

    }
  ], cb);
}
function create(connections, dataTarget, cb) {
  async.waterfall([
    function validateParams(cb) {
      validate(dataTarget).hasno(CONSTANTS.DATA_TARGET_ID, function(err) {
        if (err) {
          return cb(buildErrorResponse({error: new Error("Data Target ID Should Not Be Included When Creating A Data Target"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS}));
        }
      });

      cb(undefined, dataTarget);
    },
    function createDataTarget(dataTargetJSON, cb) {
      dataTargetJSON = sanitiseJSON(dataTargetJSON);

      var DataTarget = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_TARGET);
      var newDataTarget = new DataTarget(dataTargetJSON);

      newDataTarget.save(function(err) {
        if (err) {
          return cb(buildErrorResponse({
            error: err,
            userDetail: "Invalid Data Target Creation Data.",
            systemDetail: err.errors,
            code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS
          }));
        }

        return cb(undefined, newDataTarget.toJSON());
      });

    }
  ], cb);
}
function create ( connections , dataTarget , cb ) { async . waterfall ( [ function validateParams ( cb ) { validate ( dataTarget ) . hasno ( CONSTANTS . DATA_TARGET_ID , function ( err ) { if ( err ) { return cb ( buildErrorResponse ( { error : new Error ( "Data Target ID Should Not Be Included When Creating A Data Target" ) , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } } ) ; cb ( undefined , dataTarget ) ; } , function createDataTarget ( dataTargetJSON , cb ) { dataTargetJSON = sanitiseJSON ( dataTargetJSON ) ; var DataTarget = models . get ( connections . mongooseConnection , models . MODELNAMES . DATA_TARGET ) ; var newDataTarget = new DataTarget ( dataTargetJSON ) ; newDataTarget . save ( function ( err ) { if ( err ) { return cb ( buildErrorResponse ( { error : err , userDetail : "Invalid Data Target Creation Data." , systemDetail : err . errors , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } return cb ( undefined , newDataTarget . toJSON ( ) ) ; } ) ; } ] , cb ) ; }
Creating A New Data Target
@param connections
@param dataTarget
@param cb
Creating A New Data Target