Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

isPathExcluded.js 731B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const isDefiningProjection = require('./isDefiningProjection');
  3. /*!
  4. * Determines if `path` is excluded by `projection`
  5. *
  6. * @param {Object} projection
  7. * @param {string} path
  8. * @return {Boolean}
  9. */
  10. module.exports = function isPathExcluded(projection, path) {
  11. if (path === '_id') {
  12. return projection._id === 0;
  13. }
  14. const paths = Object.keys(projection);
  15. let type = null;
  16. for (const _path of paths) {
  17. if (isDefiningProjection(projection[_path])) {
  18. type = projection[path] === 1 ? 'inclusive' : 'exclusive';
  19. break;
  20. }
  21. }
  22. if (type === 'inclusive') {
  23. return projection[path] !== 1;
  24. }
  25. if (type === 'exclusive') {
  26. return projection[path] === 0;
  27. }
  28. return false;
  29. };