lib/impl/exportSubmissions.js
function buildCSVsForSingleForm(formSubmissionModel, params, formId, callback) {
  logger.debug("buildCSVsForSingleForm", params, formId);

  var date = params.date;
  var searchParams = params.searchParams || {};
  var fieldHeader = searchParams.fieldHeader;
  var downloadUrl = searchParams.downloadUrl || "";

  formId = formId.toString();

  params.statusUpdaterFunction({
    message: "Starting export of submissions for form with ID:" + formId
  });

  generateQuery(_.defaults({
    formId: formId
  }, searchParams), function(err, singleFormQuery) {
    if (err) {
      return callback(err);
    }

    async.waterfall([
      async.apply(buildCompositeForm, formSubmissionModel, formId, singleFormQuery, params.statusUpdaterFunction),
      function buildSubmissionCSVForSingleForm(mergedFields, formName, cb) {
        buildCSVsForSingleMergedForm(formSubmissionModel, {
          date: date,
          fieldHeader: fieldHeader,
          downloadUrl: downloadUrl,
          mergedFields: mergedFields,
          formName: formName,
          formId: formId,
          exportCounter: params.exportCounter,
          singleFormQuery: singleFormQuery,
          statusUpdaterFunction: params.statusUpdaterFunction
        }, cb);
      }
    ], callback);
  });
}
function buildCSVsForSingleForm(formSubmissionModel, params, formId, callback) {
  logger.debug("buildCSVsForSingleForm", params, formId);

  var date = params.date;
  var searchParams = params.searchParams || {};
  var fieldHeader = searchParams.fieldHeader;
  var downloadUrl = searchParams.downloadUrl || "";

  formId = formId.toString();

  params.statusUpdaterFunction({
    message: "Starting export of submissions for form with ID:" + formId
  });

  generateQuery(_.defaults({
    formId: formId
  }, searchParams), function(err, singleFormQuery) {
    if (err) {
      return callback(err);
    }

    async.waterfall([
      async.apply(buildCompositeForm, formSubmissionModel, formId, singleFormQuery, params.statusUpdaterFunction),
      function buildSubmissionCSVForSingleForm(mergedFields, formName, cb) {
        buildCSVsForSingleMergedForm(formSubmissionModel, {
          date: date,
          fieldHeader: fieldHeader,
          downloadUrl: downloadUrl,
          mergedFields: mergedFields,
          formName: formName,
          formId: formId,
          exportCounter: params.exportCounter,
          singleFormQuery: singleFormQuery,
          statusUpdaterFunction: params.statusUpdaterFunction
        }, cb);
      }
    ], callback);
  });
}
function buildCSVsForSingleForm ( formSubmissionModel , params , formId , callback ) { logger . debug ( "buildCSVsForSingleForm" , params , formId ) ; var date = params . date ; var searchParams = params . searchParams || { } ; var fieldHeader = searchParams . fieldHeader ; var downloadUrl = searchParams . downloadUrl || "" ; formId = formId . toString ( ) ; params . statusUpdaterFunction ( { message : "Starting export of submissions for form with ID:" + formId } ) ; generateQuery ( _ . defaults ( { formId : formId } , searchParams ) , function ( err , singleFormQuery ) { if ( err ) { return callback ( err ) ; } async . waterfall ( [ async . apply ( buildCompositeForm , formSubmissionModel , formId , singleFormQuery , params . statusUpdaterFunction ) , function buildSubmissionCSVForSingleForm ( mergedFields , formName , cb ) { buildCSVsForSingleMergedForm ( formSubmissionModel , { date : date , fieldHeader : fieldHeader , downloadUrl : downloadUrl , mergedFields : mergedFields , formName : formName , formId : formId , exportCounter : params . exportCounter , singleFormQuery : singleFormQuery , statusUpdaterFunction : params . statusUpdaterFunction } , cb ) ; } ] , callback ) ; } ) ; }
buildCSVsForSingleForm - Generating the full CSV file for a single form.

@param  {Model}    formSubmissionModel description
@param  {object}   params
@param  {function} params.statusUpdaterFunction                Function to update the status of the export.
@param  {string}   params.formId
@param  {string}   params.date                                 Formatted date of export
@param  {object}   params.searchParams                         Submission Parameters To Search By
@param  {array}    params.searchParams.formId                  Array of form IDs to search for
@param  {array}    params.searchParams.subid                    Array of submission IDs to search for
@param  {string} params.searchParams.filter                    A string value to filter the submissions by metadata
@param  {array} params.searchParams.appId                      Array of Project IDs to search for
@param  {string} params.searchParams.fieldHeader               Field header to use (fieldName or fieldCode)
@param  {string} params.searchParams.downloadUrl               URL to use for file downloads
@param  {number} params.exportCounter.numSubmissionsToExport   The total number of submissions to export
@param  {number} params.exportCounter.numSubsExported          The total number of submissions exported to date
@param  {string} formId                                        The ID of the form to export
@param  {function} callback
@return {type}
buildCSVsForSingleForm - Generating the full CSV file for a single form .