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