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.

castFilterPath.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. module.exports = function castFilterPath(query, schematype, val) {
  3. const ctx = query;
  4. const any$conditionals = Object.keys(val).some(function(k) {
  5. return k.charAt(0) === '$' && k !== '$id' && k !== '$ref';
  6. });
  7. if (!any$conditionals) {
  8. return schematype.castForQueryWrapper({
  9. val: val,
  10. context: ctx
  11. });
  12. }
  13. const ks = Object.keys(val);
  14. let k = ks.length;
  15. while (k--) {
  16. const $cond = ks[k];
  17. const nested = val[$cond];
  18. if ($cond === '$not') {
  19. if (nested && schematype && !schematype.caster) {
  20. const _keys = Object.keys(nested);
  21. if (_keys.length && _keys[0].charAt(0) === '$') {
  22. for (const key in nested) {
  23. nested[key] = schematype.castForQueryWrapper({
  24. $conditional: key,
  25. val: nested[key],
  26. context: ctx
  27. });
  28. }
  29. } else {
  30. val[$cond] = schematype.castForQueryWrapper({
  31. $conditional: $cond,
  32. val: nested,
  33. context: ctx
  34. });
  35. }
  36. continue;
  37. }
  38. // cast(schematype.caster ? schematype.caster.schema : schema, nested, options, context);
  39. } else {
  40. val[$cond] = schematype.castForQueryWrapper({
  41. $conditional: $cond,
  42. val: nested,
  43. context: ctx
  44. });
  45. }
  46. }
  47. return val;
  48. };