lib/common/misc.js
function buildFormFileSizes(submissions) {
  //Grouping By Form Id
  var fileSizesByForm = _.groupBy(submissions, 'formId');

  //Getting all files associated with the submissions
  fileSizesByForm = _.mapObject(fileSizesByForm, function(formSubs) {

    //Getting File Sizes For All Entries In All Submissions Related To formId
    var allSubmissionSizes = _.map(formSubs, function(submission) {

      //For a single submission, get all file sizes
      var submissionFileSizes = _.map(submission.formFields, function(formField) {
        return _.map(_.compact(formField.fieldValues), function(fieldValue) {
          return fieldValue.fileSize;
        });
      });

      var totalSize = _.compact(_.flatten(submissionFileSizes));

      //Adding all the file sizes for a single submission.
      return _.reduce(totalSize, function(memo, fileSize) {
        return memo + fileSize;
      }, 0);
    });

    //Adding all file sizes for all submissions
    return _.reduce(_.flatten(allSubmissionSizes), function(memo, fileSize) {
      return memo + fileSize;
    }, 0);
  });

  return fileSizesByForm;
}
function buildFormFileSizes(submissions) {
  //Grouping By Form Id
  var fileSizesByForm = _.groupBy(submissions, 'formId');

  //Getting all files associated with the submissions
  fileSizesByForm = _.mapObject(fileSizesByForm, function(formSubs) {

    //Getting File Sizes For All Entries In All Submissions Related To formId
    var allSubmissionSizes = _.map(formSubs, function(submission) {

      //For a single submission, get all file sizes
      var submissionFileSizes = _.map(submission.formFields, function(formField) {
        return _.map(_.compact(formField.fieldValues), function(fieldValue) {
          return fieldValue.fileSize;
        });
      });

      var totalSize = _.compact(_.flatten(submissionFileSizes));

      //Adding all the file sizes for a single submission.
      return _.reduce(totalSize, function(memo, fileSize) {
        return memo + fileSize;
      }, 0);
    });

    //Adding all file sizes for all submissions
    return _.reduce(_.flatten(allSubmissionSizes), function(memo, fileSize) {
      return memo + fileSize;
    }, 0);
  });

  return fileSizesByForm;
}
function buildFormFileSizes ( submissions ) { //Grouping By Form Id var fileSizesByForm = _ . groupBy ( submissions , 'formId' ) ; //Getting all files associated with the submissions fileSizesByForm = _ . mapObject ( fileSizesByForm , function ( formSubs ) { //Getting File Sizes For All Entries In All Submissions Related To formId var allSubmissionSizes = _ . map ( formSubs , function ( submission ) { //For a single submission, get all file sizes var submissionFileSizes = _ . map ( submission . formFields , function ( formField ) { return _ . map ( _ . compact ( formField . fieldValues ) , function ( fieldValue ) { return fieldValue . fileSize ; } ) ; } ) ; var totalSize = _ . compact ( _ . flatten ( submissionFileSizes ) ) ; //Adding all the file sizes for a single submission. return _ . reduce ( totalSize , function ( memo , fileSize ) { return memo + fileSize ; } , 0 ) ; } ) ; //Adding all file sizes for all submissions return _ . reduce ( _ . flatten ( allSubmissionSizes ) , function ( memo , fileSize ) { return memo + fileSize ; } , 0 ) ; } ) ; return fileSizesByForm ; }
Utility Function To Add All Files Storage Sizes For Submission
@param submissions
Utility Function To Add All Files Storage Sizes For Submission