@webtypen/webframez-core 0.3.23 → 0.3.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.
|
@@ -25,7 +25,27 @@ export declare class Datatable {
|
|
|
25
25
|
logAggregation: boolean;
|
|
26
26
|
defaultUnwind?: string | null;
|
|
27
27
|
disablePerPageConfig: boolean;
|
|
28
|
+
selectable: boolean;
|
|
29
|
+
selectableFunctions: {
|
|
30
|
+
[key: string]: {
|
|
31
|
+
label: string;
|
|
32
|
+
icon?: string;
|
|
33
|
+
handle: Function;
|
|
34
|
+
isAvailable?: Function;
|
|
35
|
+
payload?: any;
|
|
36
|
+
confirmMessage?: string;
|
|
37
|
+
confirmAttributes?: any;
|
|
38
|
+
};
|
|
39
|
+
} | null;
|
|
28
40
|
getInit(req: Request): Promise<any>;
|
|
41
|
+
getSelectableFunctionsDef(req: Request): Promise<{
|
|
42
|
+
label: string;
|
|
43
|
+
icon: string | undefined;
|
|
44
|
+
confirmMessage: string | undefined;
|
|
45
|
+
confirmAttributes: any;
|
|
46
|
+
apiFunction: string;
|
|
47
|
+
apiFunctionPayload: any;
|
|
48
|
+
}[] | null>;
|
|
29
49
|
getAggregation(req: Request): Promise<any>;
|
|
30
50
|
getSubAggregation(req: Request): Promise<any>;
|
|
31
51
|
getCollection(req: Request): Promise<any>;
|
|
@@ -31,10 +31,16 @@ class Datatable {
|
|
|
31
31
|
this.logAggregation = false;
|
|
32
32
|
this.defaultUnwind = null;
|
|
33
33
|
this.disablePerPageConfig = false;
|
|
34
|
+
this.selectable = false;
|
|
35
|
+
this.selectableFunctions = null;
|
|
34
36
|
}
|
|
35
37
|
getInit(req) {
|
|
36
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const out = {
|
|
39
|
+
const out = {
|
|
40
|
+
table: req.body._table,
|
|
41
|
+
selectable: this.selectable ? true : false,
|
|
42
|
+
selectableFunctions: yield this.getSelectableFunctionsDef(req),
|
|
43
|
+
};
|
|
38
44
|
const promises = [];
|
|
39
45
|
promises.push(new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
40
46
|
out.filter = yield this.getFilter(req);
|
|
@@ -72,6 +78,44 @@ class Datatable {
|
|
|
72
78
|
return out;
|
|
73
79
|
});
|
|
74
80
|
}
|
|
81
|
+
getSelectableFunctionsDef(req) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (!this.selectableFunctions) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const out = [];
|
|
87
|
+
for (let key in this.selectableFunctions) {
|
|
88
|
+
if (!this.selectableFunctions[key] || !this.selectableFunctions[key].handle) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (this.selectableFunctions[key].isAvailable && typeof this.selectableFunctions[key].isAvailable === "function") {
|
|
92
|
+
try {
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
const available = yield this.selectableFunctions[key].isAvailable(req);
|
|
95
|
+
if (!available) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
out.push({
|
|
104
|
+
label: this.selectableFunctions[key].label,
|
|
105
|
+
icon: this.selectableFunctions[key].icon,
|
|
106
|
+
confirmMessage: this.selectableFunctions[key].confirmMessage,
|
|
107
|
+
confirmAttributes: this.selectableFunctions[key].confirmAttributes,
|
|
108
|
+
apiFunction: key,
|
|
109
|
+
apiFunctionPayload: this.selectableFunctions[key].payload
|
|
110
|
+
? typeof this.selectableFunctions[key].payload === "function"
|
|
111
|
+
? yield this.selectableFunctions[key].payload(req)
|
|
112
|
+
: this.selectableFunctions[key].payload
|
|
113
|
+
: null,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return out && out.length > 0 ? out : null;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
75
119
|
getAggregation(req) {
|
|
76
120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
121
|
const prefix = [];
|
|
@@ -14,6 +14,7 @@ const Controller_1 = require("../Controller/Controller");
|
|
|
14
14
|
const DatatableRegistry_1 = require("./DatatableRegistry");
|
|
15
15
|
class DatatableController extends Controller_1.Controller {
|
|
16
16
|
restApi(req, res) {
|
|
17
|
+
var _a;
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
if (!req.body._table || req.body._table.trim() === "") {
|
|
19
20
|
return res.status(404).send({
|
|
@@ -42,6 +43,45 @@ class DatatableController extends Controller_1.Controller {
|
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
const table = new tableClass();
|
|
46
|
+
if (req.body.apiFunction && typeof req.body.apiFunction === "string" && req.body.apiFunction.trim() !== "") {
|
|
47
|
+
const func = (_a = table.selectableFunctions) === null || _a === void 0 ? void 0 : _a[req.body.apiFunction];
|
|
48
|
+
if (!func || !func.handle) {
|
|
49
|
+
return res.status(404).send({
|
|
50
|
+
status: "error",
|
|
51
|
+
message: "Unknown api-function ...",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (func.isAvailable) {
|
|
55
|
+
try {
|
|
56
|
+
const available = yield func.isAvailable(req);
|
|
57
|
+
if (!available) {
|
|
58
|
+
return res.status(403).send({
|
|
59
|
+
status: "error",
|
|
60
|
+
message: "Api-function not available ...",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
return res.status(403).send({
|
|
66
|
+
status: "error",
|
|
67
|
+
message: e instanceof Error ? e.message : "Api-function not available ...",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
yield func.handle(req, res);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error(e);
|
|
76
|
+
return res.status(500).send({
|
|
77
|
+
status: "error",
|
|
78
|
+
message: e instanceof Error ? e.message : "Unknown error ...",
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return res.send({
|
|
82
|
+
status: "success",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
45
85
|
return res.send({
|
|
46
86
|
status: "success",
|
|
47
87
|
data: yield table.getData(req),
|
package/package.json
CHANGED
|
@@ -21,9 +21,25 @@ export class Datatable {
|
|
|
21
21
|
logAggregation = false;
|
|
22
22
|
defaultUnwind?: string | null = null;
|
|
23
23
|
disablePerPageConfig = false;
|
|
24
|
+
selectable = false;
|
|
25
|
+
selectableFunctions: {
|
|
26
|
+
[key: string]: {
|
|
27
|
+
label: string;
|
|
28
|
+
icon?: string;
|
|
29
|
+
handle: Function;
|
|
30
|
+
isAvailable?: Function;
|
|
31
|
+
payload?: any;
|
|
32
|
+
confirmMessage?: string;
|
|
33
|
+
confirmAttributes?: any;
|
|
34
|
+
};
|
|
35
|
+
} | null = null;
|
|
24
36
|
|
|
25
37
|
async getInit(req: Request) {
|
|
26
|
-
const out: any = {
|
|
38
|
+
const out: any = {
|
|
39
|
+
table: req.body._table,
|
|
40
|
+
selectable: this.selectable ? true : false,
|
|
41
|
+
selectableFunctions: await this.getSelectableFunctionsDef(req),
|
|
42
|
+
};
|
|
27
43
|
const promises = [];
|
|
28
44
|
promises.push(
|
|
29
45
|
new Promise(async (resolve) => {
|
|
@@ -71,6 +87,45 @@ export class Datatable {
|
|
|
71
87
|
return out;
|
|
72
88
|
}
|
|
73
89
|
|
|
90
|
+
async getSelectableFunctionsDef(req: Request) {
|
|
91
|
+
if (!this.selectableFunctions) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const out = [];
|
|
96
|
+
for (let key in this.selectableFunctions) {
|
|
97
|
+
if (!this.selectableFunctions[key] || !this.selectableFunctions[key].handle) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (this.selectableFunctions[key].isAvailable && typeof this.selectableFunctions[key].isAvailable === "function") {
|
|
102
|
+
try {
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
const available = await this.selectableFunctions[key].isAvailable(req);
|
|
105
|
+
if (!available) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
} catch (e) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
out.push({
|
|
114
|
+
label: this.selectableFunctions[key].label,
|
|
115
|
+
icon: this.selectableFunctions[key].icon,
|
|
116
|
+
confirmMessage: this.selectableFunctions[key].confirmMessage,
|
|
117
|
+
confirmAttributes: this.selectableFunctions[key].confirmAttributes,
|
|
118
|
+
apiFunction: key,
|
|
119
|
+
apiFunctionPayload: this.selectableFunctions[key].payload
|
|
120
|
+
? typeof this.selectableFunctions[key].payload === "function"
|
|
121
|
+
? await this.selectableFunctions[key].payload(req)
|
|
122
|
+
: this.selectableFunctions[key].payload
|
|
123
|
+
: null,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return out && out.length > 0 ? out : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
74
129
|
async getAggregation(req: Request) {
|
|
75
130
|
const prefix: any = [];
|
|
76
131
|
if (this.defaultUnwind && this.defaultUnwind.trim() !== "") {
|
|
@@ -36,6 +36,48 @@ export class DatatableController extends Controller {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const table = new tableClass();
|
|
39
|
+
if (req.body.apiFunction && typeof req.body.apiFunction === "string" && req.body.apiFunction.trim() !== "") {
|
|
40
|
+
const func = table.selectableFunctions?.[req.body.apiFunction];
|
|
41
|
+
if (!func || !func.handle) {
|
|
42
|
+
return res.status(404).send({
|
|
43
|
+
status: "error",
|
|
44
|
+
message: "Unknown api-function ...",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (func.isAvailable) {
|
|
49
|
+
try {
|
|
50
|
+
const available = await func.isAvailable(req);
|
|
51
|
+
if (!available) {
|
|
52
|
+
return res.status(403).send({
|
|
53
|
+
status: "error",
|
|
54
|
+
message: "Api-function not available ...",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return res.status(403).send({
|
|
59
|
+
status: "error",
|
|
60
|
+
message: e instanceof Error ? e.message : "Api-function not available ...",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
await func.handle(req, res);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error(e);
|
|
69
|
+
|
|
70
|
+
return res.status(500).send({
|
|
71
|
+
status: "error",
|
|
72
|
+
message: e instanceof Error ? e.message : "Unknown error ...",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return res.send({
|
|
77
|
+
status: "success",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
39
81
|
return res.send({
|
|
40
82
|
status: "success",
|
|
41
83
|
data: await table.getData(req),
|