@webtypen/webframez-core 0.0.41 → 0.0.43

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.
@@ -0,0 +1,6 @@
1
+ export declare const paginationList: (options: any, aggregation?: any, aggregationOptional?: any) => Promise<{
2
+ entries: null;
3
+ total: number;
4
+ perPage: number;
5
+ page: number;
6
+ }>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.paginationList = void 0;
13
+ const DBConnection_1 = require("../Database/DBConnection");
14
+ const paginationList = (options, aggregation, aggregationOptional) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const page = options.page && parseInt(options.page) > 0 ? parseInt(options.page) : 0;
16
+ const perPage = options.perPage && parseInt(options.perPage) > 0 ? parseInt(options.perPage) : 50;
17
+ const connection = yield DBConnection_1.DBConnection.getConnection();
18
+ const collection = connection.client.db(null).collection(options.collection);
19
+ const promises = [];
20
+ let total = 0;
21
+ promises.push(new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const temp = yield collection
23
+ .aggregate([
24
+ ...(aggregation && aggregation.length > 0 ? aggregation : []),
25
+ {
26
+ $group: {
27
+ _id: null,
28
+ count: { $sum: 1 },
29
+ },
30
+ },
31
+ ])
32
+ .toArray();
33
+ if (temp && temp[0] && temp[0].count && parseInt(temp[0].count) > 0) {
34
+ total = temp[0].count;
35
+ }
36
+ resolve();
37
+ })));
38
+ let entries = null;
39
+ promises.push(new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
40
+ entries = yield collection
41
+ .aggregate([
42
+ ...(aggregation && aggregation.length > 0 ? aggregation : []),
43
+ {
44
+ $skip: page * perPage,
45
+ },
46
+ {
47
+ $limit: perPage,
48
+ },
49
+ ...(aggregationOptional && aggregationOptional.length > 0 ? aggregationOptional : []),
50
+ ])
51
+ .toArray();
52
+ resolve();
53
+ })));
54
+ yield Promise.all(promises);
55
+ return {
56
+ entries: entries,
57
+ total: total,
58
+ perPage: perPage,
59
+ page: page,
60
+ };
61
+ });
62
+ exports.paginationList = paginationList;
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./Config";
2
2
  export * from "./Functions/StringFunctions";
3
3
  export * from "./Functions/NumericFunctions";
4
+ export * from "./Functions/PaginationFunctions";
4
5
  export * from "./Commands/ConsoleCommand";
5
6
  export * from "./BaseKernelWeb";
6
7
  export * from "./BaseKernelConsole";
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Config"), exports);
18
18
  __exportStar(require("./Functions/StringFunctions"), exports);
19
19
  __exportStar(require("./Functions/NumericFunctions"), exports);
20
+ __exportStar(require("./Functions/PaginationFunctions"), exports);
20
21
  __exportStar(require("./Commands/ConsoleCommand"), exports);
21
22
  __exportStar(require("./BaseKernelWeb"), exports);
22
23
  __exportStar(require("./BaseKernelConsole"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
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",
@@ -0,0 +1,58 @@
1
+ import { DBConnection } from "../Database/DBConnection";
2
+
3
+ export const paginationList = async (options: any, aggregation?: any, aggregationOptional?: any) => {
4
+ const page = options.page && parseInt(options.page) > 0 ? parseInt(options.page) : 0;
5
+ const perPage = options.perPage && parseInt(options.perPage) > 0 ? parseInt(options.perPage) : 50;
6
+ const connection = await DBConnection.getConnection();
7
+ const collection = connection.client.db(null).collection(options.collection);
8
+
9
+ const promises = [];
10
+ let total = 0;
11
+ promises.push(
12
+ new Promise(async (resolve: Function) => {
13
+ const temp = await collection
14
+ .aggregate([
15
+ ...(aggregation && aggregation.length > 0 ? aggregation : []),
16
+ {
17
+ $group: {
18
+ _id: null,
19
+ count: { $sum: 1 },
20
+ },
21
+ },
22
+ ])
23
+ .toArray();
24
+ if (temp && temp[0] && temp[0].count && parseInt(temp[0].count) > 0) {
25
+ total = temp[0].count;
26
+ }
27
+ resolve();
28
+ })
29
+ );
30
+
31
+ let entries = null;
32
+ promises.push(
33
+ new Promise(async (resolve: Function) => {
34
+ entries = await collection
35
+ .aggregate([
36
+ ...(aggregation && aggregation.length > 0 ? aggregation : []),
37
+ {
38
+ $skip: page * perPage,
39
+ },
40
+ {
41
+ $limit: perPage,
42
+ },
43
+ ...(aggregationOptional && aggregationOptional.length > 0 ? aggregationOptional : []),
44
+ ])
45
+ .toArray();
46
+ resolve();
47
+ })
48
+ );
49
+
50
+ await Promise.all(promises);
51
+
52
+ return {
53
+ entries: entries,
54
+ total: total,
55
+ perPage: perPage,
56
+ page: page,
57
+ };
58
+ };
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./Config";
2
2
  export * from "./Functions/StringFunctions";
3
3
  export * from "./Functions/NumericFunctions";
4
+ export * from "./Functions/PaginationFunctions";
4
5
  export * from "./Commands/ConsoleCommand";
5
6
  export * from "./BaseKernelWeb";
6
7
  export * from "./BaseKernelConsole";