c2-mongoose 2.1.441 → 2.1.443

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.
@@ -76,7 +76,7 @@ var GroupV3FlowItem = /** @class */ (function () {
76
76
  groupsClauses.push(projectClause);
77
77
  if (detailed && (filters === null || filters === void 0 ? void 0 : filters.orderBy)) {
78
78
  var orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy];
79
- var docOrderBy = orderBy.filter(function (o) { return typeof o === 'string' && o.startsWith('doc.'); });
79
+ var docOrderBy = orderBy.filter(function (o) { return typeof o === 'string' && o.startsWith('docs.'); });
80
80
  var sortByFields = {};
81
81
  for (var _i = 0, docOrderBy_1 = docOrderBy; _i < docOrderBy_1.length; _i++) {
82
82
  var o = docOrderBy_1[_i];
@@ -1,5 +1,5 @@
1
1
  declare class SortV3FlowItem {
2
- execute(orderBy: string | string[], orderSense: string): any[];
2
+ execute(orderBy: string, orderSense: string): any[];
3
3
  }
4
4
  declare const _default: SortV3FlowItem;
5
5
  export default _default;
@@ -4,16 +4,14 @@ var SortV3FlowItem = /** @class */ (function () {
4
4
  function SortV3FlowItem() {
5
5
  }
6
6
  SortV3FlowItem.prototype.execute = function (orderBy, orderSense) {
7
- if (Array.isArray(orderBy)) {
8
- return orderBy.map(function (order) {
9
- var _a;
10
- return _a = {},
11
- _a[order] = orderSense === "desc" ? -1 : 1,
12
- _a;
13
- });
7
+ var ordenation = orderBy.split(',').map(function (field) { return field.trim(); });
8
+ if (!ordenation.length) {
9
+ return [{ $sort: { _id: orderSense === "desc" ? -1 : 1 } }];
14
10
  }
15
11
  var sort = {};
16
- sort[orderBy !== null && orderBy !== void 0 ? orderBy : "_id"] = orderSense === "desc" ? -1 : 1;
12
+ ordenation.forEach(function (order) {
13
+ sort[order] = orderSense === "desc" ? -1 : 1;
14
+ });
17
15
  return [{ $sort: sort }];
18
16
  };
19
17
  return SortV3FlowItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.441",
3
+ "version": "2.1.443",
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",
@@ -81,7 +81,7 @@ class GroupV3FlowItem {
81
81
 
82
82
  if (detailed && filters?.orderBy) {
83
83
  const orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy]
84
- const docOrderBy = orderBy.filter((o: string) => typeof o === 'string' && o.startsWith('doc.'))
84
+ const docOrderBy = orderBy.filter((o: string) => typeof o === 'string' && o.startsWith('docs.'))
85
85
  const sortByFields: Record<string, 1 | -1> = {}
86
86
  for (const o of docOrderBy) {
87
87
  sortByFields[o.replace(/^doc\./, '')] = filters.orderSense === 'desc' ? -1 : 1
@@ -1,16 +1,16 @@
1
1
  class SortV3FlowItem {
2
- execute(orderBy: string | string[], orderSense: string): any[] {
2
+ execute(orderBy: string, orderSense: string): any[] {
3
3
 
4
- if (Array.isArray(orderBy)) {
5
- return orderBy.map((order: string) => {
6
- return {
7
- [order]: orderSense === "desc" ? -1 : 1
8
- }
9
- })
4
+ const ordenation = orderBy.split(',').map((field: string) => field.trim())
5
+
6
+ if (!ordenation.length) {
7
+ return [{ $sort: { _id: orderSense === "desc" ? -1 : 1 } }]
10
8
  }
11
9
 
12
- let sort = {} as any
13
- sort[orderBy ?? "_id"] = orderSense === "desc" ? -1 : 1
10
+ const sort = {} as any
11
+ ordenation.forEach((order: string) => {
12
+ sort[order] = orderSense === "desc" ? -1 : 1
13
+ })
14
14
  return [{ $sort: sort }]
15
15
  }
16
16
  }