lib/impl/dataSources/updateCache.js
function updateForms(params, validDataSources, invalidDataSources, cb) {
  //Only interested In Data Sources Where Data Was Actually Updated. If the data set is still the same, then no need to mark the form as updated the form.
  var dataSoucesUpdated = _.filter(validDataSources, function(dataSourceData) {
    return dataSourceData.dataChanged === true;
  });

  //Updating Any Forms That Reference Updated Data Sources
  var updatedDataSourceIds = _.map(dataSoucesUpdated, function(validDataSourceData) {
    return validDataSourceData._id;
  });

  //Need to find and update any forms associated with the data sources.
  var Form = models.get(params.connections.mongooseConnection, models.MODELNAMES.FORM);

  //Flagging Any Forms That Are Using The Updated Data Sources As Being Updated. This is useful for client/cloud apps that need to determine if they need to load the entire form again.
  Form.update({
    "dataSources.formDataSources": {"$in": updatedDataSourceIds}
  }, {
    "$set": {
      "dataSources.lastRefresh": params.currentTime
    }
  }, { multi: true }, function(err) {
    if (err) {
      return cb(buildErrorResponse({
        error: new Error("Error Updating Forms Refresh Fields"),
        code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
      }));
    }

    //No error, forms updated, moving on
    cb(undefined, validDataSources, invalidDataSources);
  });
}
function updateForms(params, validDataSources, invalidDataSources, cb) {
  //Only interested In Data Sources Where Data Was Actually Updated. If the data set is still the same, then no need to mark the form as updated the form.
  var dataSoucesUpdated = _.filter(validDataSources, function(dataSourceData) {
    return dataSourceData.dataChanged === true;
  });

  //Updating Any Forms That Reference Updated Data Sources
  var updatedDataSourceIds = _.map(dataSoucesUpdated, function(validDataSourceData) {
    return validDataSourceData._id;
  });

  //Need to find and update any forms associated with the data sources.
  var Form = models.get(params.connections.mongooseConnection, models.MODELNAMES.FORM);

  //Flagging Any Forms That Are Using The Updated Data Sources As Being Updated. This is useful for client/cloud apps that need to determine if they need to load the entire form again.
  Form.update({
    "dataSources.formDataSources": {"$in": updatedDataSourceIds}
  }, {
    "$set": {
      "dataSources.lastRefresh": params.currentTime
    }
  }, { multi: true }, function(err) {
    if (err) {
      return cb(buildErrorResponse({
        error: new Error("Error Updating Forms Refresh Fields"),
        code: ERROR_CODES.FH_FORMS_UNEXPECTED_ERROR
      }));
    }

    //No error, forms updated, moving on
    cb(undefined, validDataSources, invalidDataSources);
  });
}
function updateForms ( params , validDataSources , invalidDataSources , cb ) { //Only interested In Data Sources Where Data Was Actually Updated. If the data set is still the same, then no need to mark the form as updated the form. var dataSoucesUpdated = _ . filter ( validDataSources , function ( dataSourceData ) { return dataSourceData . dataChanged === true ; } ) ; //Updating Any Forms That Reference Updated Data Sources var updatedDataSourceIds = _ . map ( dataSoucesUpdated , function ( validDataSourceData ) { return validDataSourceData . _id ; } ) ; //Need to find and update any forms associated with the data sources. var Form = models . get ( params . connections . mongooseConnection , models . MODELNAMES . FORM ) ; //Flagging Any Forms That Are Using The Updated Data Sources As Being Updated. This is useful for client/cloud apps that need to determine if they need to load the entire form again. Form . update ( { "dataSources.formDataSources" : { "$in" : updatedDataSourceIds } } , { "$set" : { "dataSources.lastRefresh" : params . currentTime } } , { multi : true } , function ( err ) { if ( err ) { return cb ( buildErrorResponse ( { error : new Error ( "Error Updating Forms Refresh Fields" ) , code : ERROR_CODES . FH_FORMS_UNEXPECTED_ERROR } ) ) ; } //No error, forms updated, moving on cb ( undefined , validDataSources , invalidDataSources ) ; } ) ; }
Updating All Forms Associated With Valid Data Source Updates
@param params
- currentTime
- connections
@param validDataSources
@param invalidDataSources
@param cb
Updating All Forms Associated With Valid Data Source Updates