lib/impl/notification.js
function buildSubmissionReceivedMessage(subscribers, formName, formSubmission) {
  var msg = {};
  msg.subscribers = subscribers;
  msg.formId = formSubmission.formId;
  msg.appId = formSubmission.appId;
  msg.attachmentUrl = getAttachmentUrl(formSubmission);
  msg.formName = formName || "UNKNOWN FORM NAME";
  msg.submissionStatus = formSubmission.status;
  msg.appEnvironment = formSubmission.appEnvironment;
  msg.submissionStarted = formSubmission.submissionStartedTimestamp;
  msg.submissionCompleted = formSubmission.submissionCompletedTimestamp;
  msg.submissionId = formSubmission._id;
  msg.deviceIPAddress = formSubmission.deviceIPAddress;
  msg.deviceId = formSubmission.deviceId;
  msg.submittedFields = [];

  var form = formSubmission.formSubmittedAgainst;

  // build helper structures
  var fieldPageMap = {};
  var fieldSectionMap = {};
  var sectionsInPage = {};
  form.pages.forEach(function(page) {
    var currentSectionId = 'initial';
    sectionsInPage[page._id] = [currentSectionId];
    page.fields.forEach(function(field) {
      fieldPageMap[field._id] = page._id;
      if (field.type === 'sectionBreak') {
        currentSectionId = field._id;
        sectionsInPage[page._id].push(currentSectionId);
      } else {
        fieldSectionMap[field._id] = currentSectionId;
      }
    });
  });

  // get structured form fields
  var pages = getStructuredFields(formSubmission, fieldPageMap, fieldSectionMap);

  // construct message
  form.pages.forEach(function(page) {
    //is this page in submission?
    if (pages[page._id]) {
      var sections = sectionsInPage[page._id];
      sections.forEach(function(section) {
        var repSections = pages[page._id][section];
        if (repSections) {
          if (repSections.length === 1) {
            repSections[0].forEach(function(formField) {
              msg.submittedFields.push(getFieldMsg(formField, formSubmission));
            });
          } else {
            repSections.forEach(function(repSection, index) {
              msg.submittedFields.push(getField(section, formSubmission).name + ' - ' + (index + 1) + ':');
              repSection.forEach(function(formField) {
                msg.submittedFields.push(getFieldMsg(formField, formSubmission));
              });
            });
          }
        }
      });
    }
  });

  return msg;
}
function buildSubmissionReceivedMessage(subscribers, formName, formSubmission) {
  var msg = {};
  msg.subscribers = subscribers;
  msg.formId = formSubmission.formId;
  msg.appId = formSubmission.appId;
  msg.attachmentUrl = getAttachmentUrl(formSubmission);
  msg.formName = formName || "UNKNOWN FORM NAME";
  msg.submissionStatus = formSubmission.status;
  msg.appEnvironment = formSubmission.appEnvironment;
  msg.submissionStarted = formSubmission.submissionStartedTimestamp;
  msg.submissionCompleted = formSubmission.submissionCompletedTimestamp;
  msg.submissionId = formSubmission._id;
  msg.deviceIPAddress = formSubmission.deviceIPAddress;
  msg.deviceId = formSubmission.deviceId;
  msg.submittedFields = [];

  var form = formSubmission.formSubmittedAgainst;

  // build helper structures
  var fieldPageMap = {};
  var fieldSectionMap = {};
  var sectionsInPage = {};
  form.pages.forEach(function(page) {
    var currentSectionId = 'initial';
    sectionsInPage[page._id] = [currentSectionId];
    page.fields.forEach(function(field) {
      fieldPageMap[field._id] = page._id;
      if (field.type === 'sectionBreak') {
        currentSectionId = field._id;
        sectionsInPage[page._id].push(currentSectionId);
      } else {
        fieldSectionMap[field._id] = currentSectionId;
      }
    });
  });

  // get structured form fields
  var pages = getStructuredFields(formSubmission, fieldPageMap, fieldSectionMap);

  // construct message
  form.pages.forEach(function(page) {
    //is this page in submission?
    if (pages[page._id]) {
      var sections = sectionsInPage[page._id];
      sections.forEach(function(section) {
        var repSections = pages[page._id][section];
        if (repSections) {
          if (repSections.length === 1) {
            repSections[0].forEach(function(formField) {
              msg.submittedFields.push(getFieldMsg(formField, formSubmission));
            });
          } else {
            repSections.forEach(function(repSection, index) {
              msg.submittedFields.push(getField(section, formSubmission).name + ' - ' + (index + 1) + ':');
              repSection.forEach(function(formField) {
                msg.submittedFields.push(getFieldMsg(formField, formSubmission));
              });
            });
          }
        }
      });
    }
  });

  return msg;
}
function buildSubmissionReceivedMessage ( subscribers , formName , formSubmission ) { var msg = { } ; msg . subscribers = subscribers ; msg . formId = formSubmission . formId ; msg . appId = formSubmission . appId ; msg . attachmentUrl = getAttachmentUrl ( formSubmission ) ; msg . formName = formName || "UNKNOWN FORM NAME" ; msg . submissionStatus = formSubmission . status ; msg . appEnvironment = formSubmission . appEnvironment ; msg . submissionStarted = formSubmission . submissionStartedTimestamp ; msg . submissionCompleted = formSubmission . submissionCompletedTimestamp ; msg . submissionId = formSubmission . _id ; msg . deviceIPAddress = formSubmission . deviceIPAddress ; msg . deviceId = formSubmission . deviceId ; msg . submittedFields = [ ] ; var form = formSubmission . formSubmittedAgainst ; // build helper structures var fieldPageMap = { } ; var fieldSectionMap = { } ; var sectionsInPage = { } ; form . pages . forEach ( function ( page ) { var currentSectionId = 'initial' ; sectionsInPage [ page . _id ] = [ currentSectionId ] ; page . fields . forEach ( function ( field ) { fieldPageMap [ field . _id ] = page . _id ; if ( field . type === 'sectionBreak' ) { currentSectionId = field . _id ; sectionsInPage [ page . _id ] . push ( currentSectionId ) ; } else { fieldSectionMap [ field . _id ] = currentSectionId ; } } ) ; } ) ; // get structured form fields var pages = getStructuredFields ( formSubmission , fieldPageMap , fieldSectionMap ) ; // construct message form . pages . forEach ( function ( page ) { //is this page in submission? if ( pages [ page . _id ] ) { var sections = sectionsInPage [ page . _id ] ; sections . forEach ( function ( section ) { var repSections = pages [ page . _id ] [ section ] ; if ( repSections ) { if ( repSections . length === 1 ) { repSections [ 0 ] . forEach ( function ( formField ) { msg . submittedFields . push ( getFieldMsg ( formField , formSubmission ) ) ; } ) ; } else { repSections . forEach ( function ( repSection , index ) { msg . submittedFields . push ( getField ( section , formSubmission ) . name + ' - ' + ( index + 1 ) + ':' ) ; repSection . forEach ( function ( formField ) { msg . submittedFields . push ( getFieldMsg ( formField , formSubmission ) ) ; } ) ; } ) ; } } } ) ; } } ) ; return msg ; }
export for tests
export for tests