checkEmbeddedDiscriminatorKeyProjection.js 512 B

123456789101112
  1. 'use strict';
  2. module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection, path, schema, selected, addedPaths) {
  3. const userProjectedInPath = Object.keys(userProjection).
  4. reduce((cur, key) => cur || key.startsWith(path + '.'), false);
  5. const _discriminatorKey = path + '.' + schema.options.discriminatorKey;
  6. if (!userProjectedInPath &&
  7. addedPaths.length === 1 &&
  8. addedPaths[0] === _discriminatorKey) {
  9. selected.splice(selected.indexOf(_discriminatorKey), 1);
  10. }
  11. };