All files / latest/src/handlers/get/src validateOutput.js

100% Statements 23/23
100% Branches 7/7
100% Functions 2/2
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1361x 931x 931x 1361x 46x 46x 384x 384x 1x 1x  
/**
 * Logical check whether element is an object
 */
const isElementObject = (element) => (element && typeof element === 'object');
 
/**
 * Validate output and return newTempObject and boolean whether getAll should continue
 * for next element
 * @param {Object} tempObject - object/array of current iteration
 * @param {Boolean} isLastIteration - indicator whether it is the final iteration
 * @returns {Object} Object with shouldItContinue and newTempObject
 */
const validateOutput = (tempObject, isLastIteration) => {
  if (isElementObject(tempObject)) {
    return { shouldItContinue: true, newTempObject: tempObject };
  }
  if (!isLastIteration) {
    return { shouldItContinue: false, newTempObject: undefined };
  }
  return { shouldItContinue: false, newTempObject: tempObject };
};
 
module.exports = validateOutput;