@ackplus/nest-crud-request 0.1.18 → 0.1.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ackplus/nest-crud-request",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -14,4 +14,5 @@ export declare class WhereBuilder {
14
14
  toJson(): string;
15
15
  private parseCondition;
16
16
  private updateCondition;
17
+ private mergeConditions;
17
18
  }
@@ -98,11 +98,32 @@ class WhereBuilder {
98
98
  }
99
99
  updateCondition(condition, type) {
100
100
  if (type === null) {
101
- this.whereObject = Object.assign(Object.assign({}, this.whereObject), condition);
101
+ this.mergeConditions(this.whereObject, condition);
102
102
  }
103
103
  else {
104
104
  this.whereObject[type] = [...(this.whereObject[type] || []), condition].filter(Boolean);
105
105
  }
106
106
  }
107
+ mergeConditions(target, source) {
108
+ for (const key in source) {
109
+ const sourceValue = source[key];
110
+ if (key === '$and' || key === '$or') {
111
+ if (target[key]) {
112
+ target[key] = [...(target[key] || []), ...(Array.isArray(sourceValue) ? sourceValue : [sourceValue])];
113
+ }
114
+ else {
115
+ target[key] = Array.isArray(sourceValue) ? sourceValue : [sourceValue];
116
+ }
117
+ }
118
+ else {
119
+ if (target[key] && typeof target[key] === 'object' && typeof sourceValue === 'object') {
120
+ target[key] = Object.assign(Object.assign({}, target[key]), sourceValue);
121
+ }
122
+ else {
123
+ target[key] = sourceValue;
124
+ }
125
+ }
126
+ }
127
+ }
107
128
  }
108
129
  exports.WhereBuilder = WhereBuilder;