@webtypen/webframez-core 0.2.20 → 0.2.22

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.
@@ -22,6 +22,7 @@ export declare class Datatable {
22
22
  autoApplyFilter: DatatableAutoApplyType;
23
23
  autoApplySearch: DatatableAutoApplyType;
24
24
  logAggregation: boolean;
25
+ defaultUnwind?: string | null;
25
26
  getInit(req: Request): Promise<any>;
26
27
  getAggregation(req: Request): Promise<any>;
27
28
  getSubAggregation(req: Request): Promise<any>;
@@ -25,6 +25,7 @@ class Datatable {
25
25
  this.autoApplyFilter = "begin";
26
26
  this.autoApplySearch = null;
27
27
  this.logAggregation = false;
28
+ this.defaultUnwind = null;
28
29
  }
29
30
  getInit(req) {
30
31
  return __awaiter(this, void 0, void 0, function* () {
@@ -65,23 +66,30 @@ class Datatable {
65
66
  }
66
67
  getAggregation(req) {
67
68
  return __awaiter(this, void 0, void 0, function* () {
69
+ const prefix = [];
70
+ if (this.defaultUnwind && this.defaultUnwind.trim() !== "") {
71
+ prefix.push({ $unwind: this.defaultUnwind });
72
+ }
68
73
  const aggr = typeof this.aggregation === "function" ? yield this.aggregation(req) : this.aggregation;
69
74
  if (this.autoApplyFilter && req.body.filter && typeof req.body.filter === "object") {
70
75
  if (this.autoApplyFilter === "begin") {
71
- return [{ $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }, ...aggr];
76
+ return [...prefix, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }, ...aggr];
72
77
  }
73
78
  else if (this.autoApplyFilter === "end") {
74
- return [...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }];
79
+ return [...prefix, ...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }];
75
80
  }
76
81
  }
77
82
  else if (this.autoApplySearch && req.body.search && typeof req.body.search === "object") {
78
83
  if (this.autoApplySearch === "begin") {
79
- return [{ $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }, ...aggr];
84
+ return [...prefix, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }, ...aggr];
80
85
  }
81
86
  else if (this.autoApplySearch === "end") {
82
- return [...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }];
87
+ return [...prefix, ...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }];
83
88
  }
84
89
  }
90
+ if (prefix && prefix.length > 0) {
91
+ return [...prefix, ...aggr];
92
+ }
85
93
  return aggr;
86
94
  });
87
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",
@@ -18,6 +18,7 @@ export class Datatable {
18
18
  autoApplyFilter: DatatableAutoApplyType = "begin";
19
19
  autoApplySearch: DatatableAutoApplyType = null;
20
20
  logAggregation = false;
21
+ defaultUnwind?: string | null = null;
21
22
 
22
23
  async getInit(req: Request) {
23
24
  const out: any = { table: req.body._table };
@@ -65,20 +66,29 @@ export class Datatable {
65
66
  }
66
67
 
67
68
  async getAggregation(req: Request) {
69
+ const prefix: any = [];
70
+ if (this.defaultUnwind && this.defaultUnwind.trim() !== "") {
71
+ prefix.push({ $unwind: this.defaultUnwind });
72
+ }
73
+
68
74
  const aggr = typeof this.aggregation === "function" ? await this.aggregation(req) : this.aggregation;
69
75
  if (this.autoApplyFilter && req.body.filter && typeof req.body.filter === "object") {
70
76
  if (this.autoApplyFilter === "begin") {
71
- return [{ $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }, ...aggr];
77
+ return [...prefix, { $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }, ...aggr];
72
78
  } else if (this.autoApplyFilter === "end") {
73
- return [...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }];
79
+ return [...prefix, ...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }];
74
80
  }
75
81
  } else if (this.autoApplySearch && req.body.search && typeof req.body.search === "object") {
76
82
  if (this.autoApplySearch === "begin") {
77
- return [{ $match: { ...(await this.getFilterMatch(req, req.body.search)) } }, ...aggr];
83
+ return [...prefix, { $match: { ...(await this.getFilterMatch(req, req.body.search)) } }, ...aggr];
78
84
  } else if (this.autoApplySearch === "end") {
79
- return [...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.search)) } }];
85
+ return [...prefix, ...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.search)) } }];
80
86
  }
81
87
  }
88
+
89
+ if (prefix && prefix.length > 0) {
90
+ return [...prefix, ...aggr];
91
+ }
82
92
  return aggr;
83
93
  }
84
94