@cool-digital-solutions/interferir-models 1.0.99 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schemas/theme.schema.js +16 -5
- package/package.json +1 -1
|
@@ -87,18 +87,29 @@ const themeSchema = new mongoose_1.Schema({
|
|
|
87
87
|
const excludeNonNullField = (schema, options) => {
|
|
88
88
|
const { fieldName } = options;
|
|
89
89
|
const addCondition = function (next) {
|
|
90
|
-
if (!this.getQuery().hasOwnProperty(fieldName))
|
|
90
|
+
if (!this.getQuery().hasOwnProperty(fieldName)) {
|
|
91
91
|
this.where({ $or: [{ [fieldName]: { $eq: null } }, { [fieldName]: { $exists: false } }] });
|
|
92
|
+
}
|
|
92
93
|
next();
|
|
93
94
|
};
|
|
95
|
+
const hasField = (obj, field) => {
|
|
96
|
+
return !!lodash.find(obj, (value, key) => {
|
|
97
|
+
if (key === field)
|
|
98
|
+
return true;
|
|
99
|
+
if (lodash.isObject(value))
|
|
100
|
+
return hasField(value, field);
|
|
101
|
+
return false;
|
|
102
|
+
});
|
|
103
|
+
};
|
|
94
104
|
const addAggregateCondition = function (next) {
|
|
95
105
|
const pipeline = this.pipeline();
|
|
96
|
-
const
|
|
97
|
-
if (stage.$match)
|
|
98
|
-
return
|
|
106
|
+
const hasFieldInMatch = lodash.find(pipeline, (stage) => {
|
|
107
|
+
if (stage.$match) {
|
|
108
|
+
return hasField(stage.$match, fieldName);
|
|
109
|
+
}
|
|
99
110
|
return false;
|
|
100
111
|
});
|
|
101
|
-
if (!
|
|
112
|
+
if (!hasFieldInMatch)
|
|
102
113
|
this.pipeline().unshift({ $match: { $or: [{ [fieldName]: { $eq: null } }, { [fieldName]: { $exists: false } }] } });
|
|
103
114
|
next();
|
|
104
115
|
};
|