c2-mongoose 2.1.445 → 2.1.447

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.
@@ -55,7 +55,8 @@ var BuildAndQueriesFlowItem = /** @class */ (function () {
55
55
  'preSteps',
56
56
  'posSteps',
57
57
  'metadata',
58
- 'docs.'
58
+ 'docs.',
59
+ 'docsOrderSense'
59
60
  ].includes(key)) {
60
61
  return;
61
62
  }
@@ -75,27 +75,26 @@ var GroupV3FlowItem = /** @class */ (function () {
75
75
  }
76
76
  groupsClauses.push(projectClause);
77
77
  if (detailed && (filters === null || filters === void 0 ? void 0 : filters.orderBy)) {
78
- var orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy];
79
- var docOrderBy = orderBy.filter(function (o) { return typeof o === 'string' && o.startsWith('docs.'); });
80
- var sortByFields = {};
81
- for (var _i = 0, docOrderBy_1 = docOrderBy; _i < docOrderBy_1.length; _i++) {
82
- var o = docOrderBy_1[_i];
83
- sortByFields[o.replace(/^doc\./, '')] = filters.orderSense === 'desc' ? -1 : 1;
84
- }
85
- var remainingOrderBy = orderBy.filter(function (o) { return typeof o !== 'string' || !o.startsWith('doc.'); });
86
- if (Array.isArray(filters.orderBy)) {
87
- filters.orderBy = remainingOrderBy.length ? remainingOrderBy : undefined;
88
- }
89
- else {
90
- filters.orderBy = (_b = remainingOrderBy[0]) !== null && _b !== void 0 ? _b : undefined;
91
- }
92
- if (Object.keys(sortByFields).length > 0) {
78
+ var ordenation = (_b = filters.orderBy) === null || _b === void 0 ? void 0 : _b.split(',').map(function (field) { return field === null || field === void 0 ? void 0 : field.trim(); });
79
+ var sortByFields_1 = {};
80
+ ordenation === null || ordenation === void 0 ? void 0 : ordenation.filter(function (o) { return o.startsWith('docs.'); }).forEach(function (order) {
81
+ sortByFields_1[order.replace(/^docs\./, '')] = filters.docsOrderSense === 'desc' ? -1 : 1;
82
+ });
83
+ // const orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy]
84
+ // const docOrderBy = orderBy.filter((o: string) => typeof o === 'string' && o.startsWith('docs.'))
85
+ // const sortByFields: Record<string, 1 | -1> = {}
86
+ // for (const o of docOrderBy) {
87
+ // sortByFields[o.replace(/^doc\./, '')] = filters.orderSense === 'desc' ? -1 : 1
88
+ // }
89
+ var remainingOrderBy = ordenation.filter(function (o) { return typeof o !== 'string' || !o.startsWith('docs.'); });
90
+ filters.orderBy = remainingOrderBy.length ? remainingOrderBy.join(',') : undefined;
91
+ if (Object.keys(sortByFields_1).length > 0) {
93
92
  groupsClauses.push({
94
93
  $set: {
95
94
  docs: {
96
95
  $sortArray: {
97
96
  input: '$docs',
98
- sortBy: sortByFields
97
+ sortBy: sortByFields_1
99
98
  }
100
99
  }
101
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.445",
3
+ "version": "2.1.447",
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",
@@ -36,7 +36,8 @@ class BuildAndQueriesFlowItem {
36
36
  'preSteps',
37
37
  'posSteps',
38
38
  'metadata',
39
- 'docs.'
39
+ 'docs.',
40
+ 'docsOrderSense'
40
41
  ].includes(key)) {
41
42
  return
42
43
  }
@@ -80,19 +80,25 @@ class GroupV3FlowItem {
80
80
  groupsClauses.push(projectClause)
81
81
 
82
82
  if (detailed && filters?.orderBy) {
83
- const orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy]
84
- const docOrderBy = orderBy.filter((o: string) => typeof o === 'string' && o.startsWith('docs.'))
83
+
84
+
85
+ const ordenation = filters.orderBy?.split(',').map((field: string) => field?.trim())
86
+
85
87
  const sortByFields: Record<string, 1 | -1> = {}
86
- for (const o of docOrderBy) {
87
- sortByFields[o.replace(/^doc\./, '')] = filters.orderSense === 'desc' ? -1 : 1
88
- }
88
+ ordenation?.filter((o: string) => o.startsWith('docs.')).forEach((order: string) => {
89
+ sortByFields[order.replace(/^docs\./, '')] = filters.docsOrderSense === 'desc' ? -1 : 1
90
+ })
89
91
 
90
- const remainingOrderBy = orderBy.filter((o: string) => typeof o !== 'string' || !o.startsWith('doc.'))
91
- if (Array.isArray(filters.orderBy)) {
92
- filters.orderBy = remainingOrderBy.length ? remainingOrderBy : undefined
93
- } else {
94
- filters.orderBy = remainingOrderBy[0] ?? undefined
95
- }
92
+
93
+ // const orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy]
94
+ // const docOrderBy = orderBy.filter((o: string) => typeof o === 'string' && o.startsWith('docs.'))
95
+ // const sortByFields: Record<string, 1 | -1> = {}
96
+ // for (const o of docOrderBy) {
97
+ // sortByFields[o.replace(/^doc\./, '')] = filters.orderSense === 'desc' ? -1 : 1
98
+ // }
99
+
100
+ const remainingOrderBy = ordenation.filter((o: string) => typeof o !== 'string' || !o.startsWith('docs.'))
101
+ filters.orderBy = remainingOrderBy.length ? remainingOrderBy.join(',') : undefined
96
102
 
97
103
  if (Object.keys(sortByFields).length > 0) {
98
104
  groupsClauses.push({