@ewb/mongoose-query 1.1.7 → 1.1.9
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/lib/Query.d.ts +1 -0
- package/lib/Query.js +11 -6
- package/lib/QueryModel.js +3 -4
- package/package.json +1 -1
package/lib/Query.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export declare class Query<R extends object, T extends object = object, Q extend
|
|
|
41
41
|
defaultSelect(select: MongooseSortSelectValue<T>[]): void;
|
|
42
42
|
addPopulate(populate: mongoose.PopulateOptions | mongoose.PopulateOptions[]): void;
|
|
43
43
|
addRoot(query: QueryType<T>): QueryType<T>;
|
|
44
|
+
removeRoot(key: string): QueryType<T>;
|
|
44
45
|
addRootNext(query: QueryType<T>): QueryType<T>;
|
|
45
46
|
removeQuery(key: keyof QueryType<T>): void;
|
|
46
47
|
deleteKeysFromQuery(key: keyof QueryType<T>): void;
|
package/lib/Query.js
CHANGED
|
@@ -37,16 +37,15 @@ export class Query {
|
|
|
37
37
|
return this._limit;
|
|
38
38
|
}
|
|
39
39
|
get root() {
|
|
40
|
+
const modelQuery = this._addToModelQuery[this._model];
|
|
40
41
|
const root = this._root;
|
|
41
|
-
if (this._model &&
|
|
42
|
+
if (this._model && modelQuery && Object.keys(modelQuery).length) {
|
|
42
43
|
if (root) {
|
|
43
|
-
return {
|
|
44
|
-
$and: [root, this._addToModelQuery[this._model]],
|
|
45
|
-
};
|
|
44
|
+
return { $and: [root, modelQuery] };
|
|
46
45
|
}
|
|
47
|
-
return
|
|
46
|
+
return { ...modelQuery };
|
|
48
47
|
}
|
|
49
|
-
return root;
|
|
48
|
+
return { ...root };
|
|
50
49
|
}
|
|
51
50
|
get model() {
|
|
52
51
|
return this._model;
|
|
@@ -103,6 +102,12 @@ export class Query {
|
|
|
103
102
|
};
|
|
104
103
|
return this._root;
|
|
105
104
|
}
|
|
105
|
+
removeRoot(key) {
|
|
106
|
+
if (this._root && key in this._root) {
|
|
107
|
+
delete this._root[key];
|
|
108
|
+
}
|
|
109
|
+
return this._root;
|
|
110
|
+
}
|
|
106
111
|
addRootNext(query) {
|
|
107
112
|
this._rootNext = {
|
|
108
113
|
...(this._rootNext || {}),
|
package/lib/QueryModel.js
CHANGED
|
@@ -165,10 +165,9 @@ export class QueryModel {
|
|
|
165
165
|
for (const key in body) {
|
|
166
166
|
$set[`${String(sub)}.$.${key}`] = body[key];
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}, { $set });
|
|
168
|
+
const filter = query.root;
|
|
169
|
+
filter[sub] = { $elemMatch: subQuery };
|
|
170
|
+
await this._model.updateOne(filter, { $set });
|
|
172
171
|
return this.subFindOne(sub, query, subQuery);
|
|
173
172
|
}
|
|
174
173
|
async subDelete(sub, query, subQuery) {
|
package/package.json
CHANGED