not-node 6.3.13 → 6.3.14
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.
- package/package.json +1 -1
- package/src/generic/route.js +58 -0
package/package.json
CHANGED
package/src/generic/route.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
const { HttpExceptionForbidden } = require("../exceptions/http");
|
|
2
|
+
|
|
1
3
|
module.exports = ({ getLogic, before, after }) => {
|
|
2
4
|
class notGenericRoute {
|
|
5
|
+
static restrictRootAccess = false;
|
|
6
|
+
static exceptionOnRootAccess = HttpExceptionForbidden;
|
|
7
|
+
static exceptionParamsPacker = (prepared) => {
|
|
8
|
+
return [{ params: prepared }];
|
|
9
|
+
};
|
|
10
|
+
|
|
3
11
|
static before() {
|
|
4
12
|
return before(...arguments);
|
|
5
13
|
}
|
|
@@ -9,6 +17,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
9
17
|
}
|
|
10
18
|
|
|
11
19
|
static async _create(req, res, next, prepared) {
|
|
20
|
+
if (this.restrictRootAccess) {
|
|
21
|
+
throw new this.exceptionOnRootAccess(
|
|
22
|
+
...this.exceptionParamsPacker(prepared)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
12
25
|
prepared.root = true;
|
|
13
26
|
return await getLogic().create(prepared);
|
|
14
27
|
}
|
|
@@ -18,6 +31,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
18
31
|
}
|
|
19
32
|
|
|
20
33
|
static async _get(req, res, next, prepared) {
|
|
34
|
+
if (this.restrictRootAccess) {
|
|
35
|
+
throw new this.exceptionOnRootAccess(
|
|
36
|
+
...this.exceptionParamsPacker(prepared)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
21
39
|
prepared.root = true;
|
|
22
40
|
return await getLogic().get(prepared);
|
|
23
41
|
}
|
|
@@ -27,6 +45,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
27
45
|
}
|
|
28
46
|
|
|
29
47
|
static async _getByID(req, res, next, prepared) {
|
|
48
|
+
if (this.restrictRootAccess) {
|
|
49
|
+
throw new this.exceptionOnRootAccess(
|
|
50
|
+
...this.exceptionParamsPacker(prepared)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
30
53
|
prepared.root = true;
|
|
31
54
|
return await getLogic().getByID(prepared);
|
|
32
55
|
}
|
|
@@ -36,6 +59,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
static async _getRaw(req, res, next, prepared) {
|
|
62
|
+
if (this.restrictRootAccess) {
|
|
63
|
+
throw new this.exceptionOnRootAccess(
|
|
64
|
+
...this.exceptionParamsPacker(prepared)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
39
67
|
prepared.root = true;
|
|
40
68
|
return await getLogic().getRaw(prepared);
|
|
41
69
|
}
|
|
@@ -45,6 +73,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
45
73
|
}
|
|
46
74
|
|
|
47
75
|
static async _update(req, res, next, prepared) {
|
|
76
|
+
if (this.restrictRootAccess) {
|
|
77
|
+
throw new this.exceptionOnRootAccess(
|
|
78
|
+
...this.exceptionParamsPacker(prepared)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
48
81
|
prepared.root = true;
|
|
49
82
|
return await getLogic().update(prepared);
|
|
50
83
|
}
|
|
@@ -54,6 +87,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
54
87
|
}
|
|
55
88
|
|
|
56
89
|
static async _listAll(req, res, next, prepared) {
|
|
90
|
+
if (this.restrictRootAccess) {
|
|
91
|
+
throw new this.exceptionOnRootAccess(
|
|
92
|
+
...this.exceptionParamsPacker(prepared)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
57
95
|
prepared.root = true;
|
|
58
96
|
return await getLogic().listAll(prepared);
|
|
59
97
|
}
|
|
@@ -63,6 +101,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
63
101
|
}
|
|
64
102
|
|
|
65
103
|
static async _listAndCount(req, res, next, prepared) {
|
|
104
|
+
if (this.restrictRootAccess) {
|
|
105
|
+
throw new this.exceptionOnRootAccess(
|
|
106
|
+
...this.exceptionParamsPacker(prepared)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
66
109
|
prepared.root = true;
|
|
67
110
|
return await getLogic().listAndCount(prepared);
|
|
68
111
|
}
|
|
@@ -72,6 +115,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
72
115
|
}
|
|
73
116
|
|
|
74
117
|
static async _list(req, res, next, prepared) {
|
|
118
|
+
if (this.restrictRootAccess) {
|
|
119
|
+
throw new this.exceptionOnRootAccess(
|
|
120
|
+
...this.exceptionParamsPacker(prepared)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
75
123
|
prepared.root = true;
|
|
76
124
|
return await getLogic().list(prepared);
|
|
77
125
|
}
|
|
@@ -81,6 +129,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
81
129
|
}
|
|
82
130
|
|
|
83
131
|
static async _count(req, res, next, prepared) {
|
|
132
|
+
if (this.restrictRootAccess) {
|
|
133
|
+
throw new this.exceptionOnRootAccess(
|
|
134
|
+
...this.exceptionParamsPacker(prepared)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
84
137
|
prepared.root = true;
|
|
85
138
|
return await getLogic().count(prepared);
|
|
86
139
|
}
|
|
@@ -90,6 +143,11 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
90
143
|
}
|
|
91
144
|
|
|
92
145
|
static async _delete(req, res, next, prepared) {
|
|
146
|
+
if (this.restrictRootAccess) {
|
|
147
|
+
throw new this.exceptionOnRootAccess(
|
|
148
|
+
...this.exceptionParamsPacker(prepared)
|
|
149
|
+
);
|
|
150
|
+
}
|
|
93
151
|
prepared.root = true;
|
|
94
152
|
return await getLogic().delete(prepared);
|
|
95
153
|
}
|