c2-mongoose 2.1.449 → 2.1.451

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.
@@ -2,6 +2,7 @@ export interface IForeingData {
2
2
  collectionChild: string;
3
3
  parentFieldOnChild: string;
4
4
  match?: any;
5
+ sort?: any;
5
6
  }
6
7
  declare class OneToManyV3FlowItem {
7
8
  execute(foreings: IForeingData[], populate?: string): any[];
@@ -23,32 +23,40 @@ var OneToManyV3FlowItem = /** @class */ (function () {
23
23
  foreings === null || foreings === void 0 ? void 0 : foreings.forEach(function (foreing) {
24
24
  var labeled = (0, lodash_1.camelCase)(foreing.collectionChild);
25
25
  var populateClauseLookup = [];
26
+ var pipeline = [];
26
27
  if (foreing.match) {
27
- populateClauseLookup.push({
28
- $lookup: {
29
- from: foreing.collectionChild,
30
- let: { localField: '$_id' },
31
- localField: "_id",
32
- foreignField: foreing.parentFieldOnChild,
33
- as: labeled,
34
- pipeline: [
35
- {
36
- $match: foreing.match
37
- },
38
- ]
28
+ pipeline = __spreadArray(__spreadArray([], pipeline, true), [
29
+ {
30
+ $match: foreing.match
39
31
  }
40
- });
32
+ ], false);
41
33
  }
42
- else {
43
- populateClauseLookup.push({
44
- $lookup: {
45
- from: foreing.collectionChild,
46
- localField: "_id",
47
- foreignField: foreing.parentFieldOnChild,
48
- as: labeled
49
- }
50
- });
34
+ if (foreing.sort) {
35
+ pipeline = __spreadArray(__spreadArray([], pipeline, true), [
36
+ { $sort: foreing.sort }
37
+ ], false);
51
38
  }
39
+ // if (foreing.match) {
40
+ populateClauseLookup.push({
41
+ $lookup: {
42
+ from: foreing.collectionChild,
43
+ let: { localField: '$_id' },
44
+ foreignField: foreing.parentFieldOnChild,
45
+ as: labeled,
46
+ pipeline: pipeline
47
+ }
48
+ });
49
+ // }
50
+ // else {
51
+ // populateClauseLookup.push({
52
+ // $lookup: {
53
+ // from: foreing.collectionChild, // The collection where user data is stored
54
+ // localField: "_id",
55
+ // foreignField: foreing.parentFieldOnChild,
56
+ // as: labeled
57
+ // }
58
+ // })
59
+ // }
52
60
  collection = __spreadArray(__spreadArray([], collection, true), populateClauseLookup, true);
53
61
  var model = global.connectionMongoose.models[Object.keys(global.connectionMongoose.models).find(function (key) { return global.connectionMongoose.models[key].collection.name === foreing.collectionChild; })];
54
62
  if (model) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.449",
3
+ "version": "2.1.451",
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",
@@ -4,6 +4,7 @@ export interface IForeingData {
4
4
  collectionChild: string;
5
5
  parentFieldOnChild: string;
6
6
  match?: any
7
+ sort?: any
7
8
  }
8
9
 
9
10
  class OneToManyV3FlowItem {
@@ -14,33 +15,45 @@ class OneToManyV3FlowItem {
14
15
  const labeled = camelCase(foreing.collectionChild)
15
16
  const populateClauseLookup: any[] = []
16
17
 
18
+ let pipeline: any[] = []
19
+
17
20
  if (foreing.match) {
18
- populateClauseLookup.push({
19
- $lookup: {
20
- from: foreing.collectionChild, // The collection where user data is stored
21
- let: { localField: '$_id' },
22
- localField: "_id",
23
- foreignField: foreing.parentFieldOnChild,
24
- as: labeled,
25
- pipeline: [
26
- {
27
- $match:
28
- foreing.match
29
- },
30
- ]
31
- }
32
- })
33
- } else {
34
- populateClauseLookup.push({
35
- $lookup: {
36
- from: foreing.collectionChild, // The collection where user data is stored
37
- localField: "_id",
38
- foreignField: foreing.parentFieldOnChild,
39
- as: labeled
21
+ pipeline = [
22
+ ...pipeline,
23
+ {
24
+ $match: foreing.match
40
25
  }
41
- })
26
+ ]
27
+ }
28
+ if (foreing.sort) {
29
+ pipeline = [
30
+ ...pipeline,
31
+ { $sort: foreing.sort }
32
+ ]
42
33
  }
43
34
 
35
+ // if (foreing.match) {
36
+ populateClauseLookup.push({
37
+ $lookup: {
38
+ from: foreing.collectionChild, // The collection where user data is stored
39
+ let: { localField: '$_id' },
40
+ foreignField: foreing.parentFieldOnChild,
41
+ as: labeled,
42
+ pipeline: pipeline
43
+ }
44
+ })
45
+ // }
46
+ // else {
47
+ // populateClauseLookup.push({
48
+ // $lookup: {
49
+ // from: foreing.collectionChild, // The collection where user data is stored
50
+ // localField: "_id",
51
+ // foreignField: foreing.parentFieldOnChild,
52
+ // as: labeled
53
+ // }
54
+ // })
55
+ // }
56
+
44
57
  collection = [...collection, ...populateClauseLookup]
45
58
 
46
59
  let model = (global as any).connectionMongoose.models[