@webtypen/webframez-core 0.2.24 → 0.2.25
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
|
autoApplySearch: "begin" | "end" | null;
|
|
23
23
|
logAggregation: boolean;
|
|
24
24
|
defaultUnwind?: string | null;
|
|
25
|
+
disablePerPageConfig: boolean;
|
|
25
26
|
getInit(req: Request): Promise<any>;
|
|
26
27
|
getAggregation(req: Request): Promise<any>;
|
|
27
28
|
getSubAggregation(req: Request): Promise<any>;
|
|
@@ -30,6 +31,7 @@ export declare class Datatable {
|
|
|
30
31
|
page: number;
|
|
31
32
|
max_entries: any;
|
|
32
33
|
total_pages: number;
|
|
34
|
+
per_page: number;
|
|
33
35
|
entries: any;
|
|
34
36
|
sums: any;
|
|
35
37
|
}>;
|
|
@@ -26,6 +26,7 @@ class Datatable {
|
|
|
26
26
|
this.autoApplySearch = null;
|
|
27
27
|
this.logAggregation = false;
|
|
28
28
|
this.defaultUnwind = null;
|
|
29
|
+
this.disablePerPageConfig = false;
|
|
29
30
|
}
|
|
30
31
|
getInit(req) {
|
|
31
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -152,10 +153,11 @@ class Datatable {
|
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
}
|
|
156
|
+
const perPage = req.body.perPage && parseInt(req.body.perPage) > 0 && !this.disablePerPageConfig ? parseInt(req.body.perPage) : this.perPage;
|
|
155
157
|
const aggr = [
|
|
156
158
|
...(aggregation ? aggregation : []),
|
|
157
|
-
...(!hasSkip ? [{ $skip: page ? page *
|
|
158
|
-
...(!hasLimit ? [{ $limit:
|
|
159
|
+
...(!hasSkip ? [{ $skip: page ? page * perPage : 0 }] : []),
|
|
160
|
+
...(!hasLimit ? [{ $limit: perPage }] : []),
|
|
159
161
|
...(subAggregation ? subAggregation : []),
|
|
160
162
|
];
|
|
161
163
|
if (this.logAggregation) {
|
|
@@ -213,7 +215,8 @@ class Datatable {
|
|
|
213
215
|
return {
|
|
214
216
|
page: page,
|
|
215
217
|
max_entries: stats && stats[0] && stats[0].count ? stats[0].count : 0,
|
|
216
|
-
total_pages: stats && stats[0] && stats[0].count > 0 ? Math.ceil(stats[0].count /
|
|
218
|
+
total_pages: stats && stats[0] && stats[0].count > 0 ? Math.ceil(stats[0].count / perPage) : 0,
|
|
219
|
+
per_page: perPage,
|
|
217
220
|
entries: results,
|
|
218
221
|
sums: sums,
|
|
219
222
|
};
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ export class Datatable {
|
|
|
17
17
|
autoApplySearch: "begin" | "end" | null = null;
|
|
18
18
|
logAggregation = false;
|
|
19
19
|
defaultUnwind?: string | null = null;
|
|
20
|
+
disablePerPageConfig = false;
|
|
20
21
|
|
|
21
22
|
async getInit(req: Request) {
|
|
22
23
|
const out: any = { table: req.body._table };
|
|
@@ -149,10 +150,12 @@ export class Datatable {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
|
153
|
+
const perPage =
|
|
154
|
+
req.body.perPage && parseInt(req.body.perPage) > 0 && !this.disablePerPageConfig ? parseInt(req.body.perPage) : this.perPage;
|
|
152
155
|
const aggr = [
|
|
153
156
|
...(aggregation ? aggregation : []),
|
|
154
|
-
...(!hasSkip ? [{ $skip: page ? page *
|
|
155
|
-
...(!hasLimit ? [{ $limit:
|
|
157
|
+
...(!hasSkip ? [{ $skip: page ? page * perPage : 0 }] : []),
|
|
158
|
+
...(!hasLimit ? [{ $limit: perPage }] : []),
|
|
156
159
|
...(subAggregation ? subAggregation : []),
|
|
157
160
|
];
|
|
158
161
|
if (this.logAggregation) {
|
|
@@ -221,7 +224,8 @@ export class Datatable {
|
|
|
221
224
|
return {
|
|
222
225
|
page: page,
|
|
223
226
|
max_entries: stats && stats[0] && stats[0].count ? stats[0].count : 0,
|
|
224
|
-
total_pages: stats && stats[0] && stats[0].count > 0 ? Math.ceil(stats[0].count /
|
|
227
|
+
total_pages: stats && stats[0] && stats[0].count > 0 ? Math.ceil(stats[0].count / perPage) : 0,
|
|
228
|
+
per_page: perPage,
|
|
225
229
|
entries: results,
|
|
226
230
|
sums: sums,
|
|
227
231
|
};
|