c2-mongoose 2.1.314 → 2.1.316

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.
@@ -240,6 +240,15 @@ var SearcherFlow = /** @class */ (function () {
240
240
  var fieldName = key.replace('Like', '');
241
241
  condition[fieldName] = this.buildRegex(value); //{ $regex: value as any, $options: 'i' }
242
242
  }
243
+ else if (key.endsWith("AtLeastOneExists")) {
244
+ key = key.replace("AtLeastOneExists", "");
245
+ var fields = key.split('.');
246
+ if (!fields)
247
+ return condition;
248
+ // const elemMatch = {} as any
249
+ // elemMatch[lastField] = value as boolean
250
+ condition[fields[0]] = { $elemMatch: (_a = {}, _a[fields[1]] = value, _a) };
251
+ }
243
252
  else if (key.endsWith('Exists')) {
244
253
  var fieldName = key.replace('Exists', '');
245
254
  condition[fieldName] = { $exists: value };
@@ -248,15 +257,6 @@ var SearcherFlow = /** @class */ (function () {
248
257
  key = key.replace("IsEmpty", "");
249
258
  condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
250
259
  }
251
- else if (key.endsWith("AtLeastOneExists")) {
252
- key = key.replace("AtLeastOneExists", "");
253
- var lastField = key.split('.').pop();
254
- if (!lastField)
255
- return condition;
256
- // const elemMatch = {} as any
257
- // elemMatch[lastField] = value as boolean
258
- condition[key] = { $elemMatch: (_a = {}, _a[lastField] = value, _a) };
259
- }
260
260
  else {
261
261
  if (((_d = (_c = (_b = this.model) === null || _b === void 0 ? void 0 : _b.schema) === null || _c === void 0 ? void 0 : _c.paths[key]) === null || _d === void 0 ? void 0 : _d.instance) === 'Array') {
262
262
  if (!Array.isArray(value)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.314",
3
+ "version": "2.1.316",
4
4
  "description": "Lib to make any search in database mongoose and use as basic crud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -216,21 +216,21 @@ class SearcherFlow<D> {
216
216
  } else if (key.endsWith('Like')) {
217
217
  var fieldName = key.replace('Like', '')
218
218
  condition[fieldName] = this.buildRegex(value as string) //{ $regex: value as any, $options: 'i' }
219
- } else if (key.endsWith('Exists')) {
220
- var fieldName = key.replace('Exists', '')
221
- condition[fieldName] = { $exists: value as boolean }
222
- } else if (key.endsWith("IsEmpty")) {
223
- key = key.replace("IsEmpty", "");
224
- condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
225
219
  } else if (key.endsWith("AtLeastOneExists")) {
226
220
  key = key.replace("AtLeastOneExists", "");
227
221
 
228
- const lastField = key.split('.').pop()
229
- if (!lastField) return condition;
222
+ const fields = key.split('.')
223
+ if (!fields) return condition;
230
224
 
231
225
  // const elemMatch = {} as any
232
226
  // elemMatch[lastField] = value as boolean
233
- condition[key] = { $elemMatch: { [lastField]: value as boolean} }
227
+ condition[fields[0]] = { $elemMatch: { [fields[1]]: value as boolean } }
228
+ } else if (key.endsWith('Exists')) {
229
+ var fieldName = key.replace('Exists', '')
230
+ condition[fieldName] = { $exists: value as boolean }
231
+ } else if (key.endsWith("IsEmpty")) {
232
+ key = key.replace("IsEmpty", "");
233
+ condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
234
234
  } else {
235
235
  if (this.model?.schema?.paths[key]?.instance === 'Array') {
236
236
  if (!Array.isArray(value)) {