@azteam/express 1.2.173 → 1.2.176
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 +2 -2
- package/src/AdminController.js +73 -37
- package/src/Controller.js +1 -5
- package/src/Server.js +20 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azteam/express",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.176",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">= 12.0.0",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@azteam/crypto": "1.0.23",
|
|
13
13
|
"@azteam/error": "1.0.18",
|
|
14
|
-
"@azteam/http-client": "1.0.
|
|
14
|
+
"@azteam/http-client": "1.0.93",
|
|
15
15
|
"@grpc/grpc-js": "1.6.7",
|
|
16
16
|
"@grpc/proto-loader": "0.6.12",
|
|
17
17
|
"body-parser": "1.19.0",
|
package/src/AdminController.js
CHANGED
|
@@ -3,41 +3,41 @@ import {NOT_EXISTS} from '@azteam/error';
|
|
|
3
3
|
import {REQUEST_TYPE} from './constant';
|
|
4
4
|
import {rulesID} from './validate';
|
|
5
5
|
import Controller from './Controller';
|
|
6
|
-
import {adminRoleMiddleware, paginateMiddleware, validateMiddleware} from './middleware';
|
|
6
|
+
import {adminRoleMiddleware, paginateMiddleware, validateMiddleware, verifyGoogleAppMiddleware} from './middleware';
|
|
7
7
|
|
|
8
8
|
class AdminController extends Controller {
|
|
9
9
|
constructor(pathName, repository, options = {}) {
|
|
10
|
-
super(pathName, repository
|
|
11
|
-
roles: {
|
|
12
|
-
READ: 1,
|
|
13
|
-
CREATE: 2,
|
|
14
|
-
UPDATE: 3,
|
|
15
|
-
DELETE: 4,
|
|
16
|
-
RESTORE: 5,
|
|
17
|
-
DESTROY: 6,
|
|
18
|
-
}, // system roles
|
|
10
|
+
super(pathName, repository);
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
this.roles = {
|
|
13
|
+
READ: null,
|
|
14
|
+
CREATE: null,
|
|
15
|
+
UPDATE: null,
|
|
16
|
+
DELETE: null,
|
|
17
|
+
RESTORE: null,
|
|
18
|
+
DESTROY: null,
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
...options.roles,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
this.paginateOptions = options.paginateOptions || {};
|
|
24
|
+
this.guardResponse = options.guardResponse || {};
|
|
25
|
+
this.allowResponse = options.allowResponse || {};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
this.rulesCreate = options.rulesCreate || {};
|
|
28
|
+
this.rulesModify = options.rulesModify || {};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
getPaginatePublic() {
|
|
32
32
|
return {
|
|
33
|
+
disabled: !this.roles.READ,
|
|
33
34
|
path: '/',
|
|
34
35
|
method: [
|
|
35
|
-
adminRoleMiddleware([this.
|
|
36
|
-
paginateMiddleware(this.
|
|
36
|
+
adminRoleMiddleware([this.roles.READ]),
|
|
37
|
+
paginateMiddleware(this.paginateOptions),
|
|
37
38
|
async (req, res) => {
|
|
38
39
|
const paginateData = await this.repository.find(req.query, req.paginate);
|
|
39
|
-
|
|
40
|
-
return res.success(paginateData, this.options.guardResponse, this.options.allowResponse);
|
|
40
|
+
return res.success(paginateData, this.guardResponse, this.allowResponse);
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
};
|
|
@@ -45,14 +45,15 @@ class AdminController extends Controller {
|
|
|
45
45
|
|
|
46
46
|
getPaginateTrash() {
|
|
47
47
|
return {
|
|
48
|
+
disabled: !this.roles.READ,
|
|
48
49
|
path: '/',
|
|
49
50
|
method: [
|
|
50
|
-
adminRoleMiddleware([this.
|
|
51
|
-
paginateMiddleware(this.
|
|
51
|
+
adminRoleMiddleware([this.roles.READ]),
|
|
52
|
+
paginateMiddleware(this.paginateOptions),
|
|
52
53
|
async (req, res) => {
|
|
53
54
|
const paginateData = await this.repository.findTrash(req.query, req.paginate);
|
|
54
55
|
|
|
55
|
-
return res.success(paginateData, this.
|
|
56
|
+
return res.success(paginateData, this.guardResponse, this.allowResponse);
|
|
56
57
|
},
|
|
57
58
|
],
|
|
58
59
|
};
|
|
@@ -60,14 +61,15 @@ class AdminController extends Controller {
|
|
|
60
61
|
|
|
61
62
|
getOnePublic() {
|
|
62
63
|
return {
|
|
64
|
+
disabled: !this.roles.READ,
|
|
63
65
|
path: '/:id',
|
|
64
66
|
method: [
|
|
65
|
-
adminRoleMiddleware([this.
|
|
67
|
+
adminRoleMiddleware([this.roles.READ]),
|
|
66
68
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
67
69
|
async (req, res) => {
|
|
68
70
|
const item = await this.repository.findOneById(req.params.id);
|
|
69
71
|
if (!item) return res.error(NOT_EXISTS);
|
|
70
|
-
return res.success(item, this.
|
|
72
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
71
73
|
},
|
|
72
74
|
],
|
|
73
75
|
};
|
|
@@ -75,14 +77,15 @@ class AdminController extends Controller {
|
|
|
75
77
|
|
|
76
78
|
getOneTrash() {
|
|
77
79
|
return {
|
|
80
|
+
disabled: !this.roles.READ,
|
|
78
81
|
path: '/:id',
|
|
79
82
|
method: [
|
|
80
|
-
adminRoleMiddleware([this.
|
|
83
|
+
adminRoleMiddleware([this.roles.READ]),
|
|
81
84
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
82
85
|
async (req, res) => {
|
|
83
86
|
const item = await this.repository.findOneTrashById(req.params.id);
|
|
84
87
|
if (!item) return res.error(NOT_EXISTS);
|
|
85
|
-
return res.success(item, this.
|
|
88
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
86
89
|
},
|
|
87
90
|
],
|
|
88
91
|
};
|
|
@@ -98,10 +101,11 @@ class AdminController extends Controller {
|
|
|
98
101
|
|
|
99
102
|
postCreatePublic() {
|
|
100
103
|
return {
|
|
104
|
+
disabled: !this.roles.CREATE,
|
|
101
105
|
path: '/',
|
|
102
106
|
method: [
|
|
103
|
-
adminRoleMiddleware([this.
|
|
104
|
-
validateMiddleware(REQUEST_TYPE.BODY, this.
|
|
107
|
+
adminRoleMiddleware([this.roles.CREATE]),
|
|
108
|
+
validateMiddleware(REQUEST_TYPE.BODY, this.rulesCreate),
|
|
105
109
|
async (req, res) => {
|
|
106
110
|
const data = await this.beforeCreate(req.body, req.user);
|
|
107
111
|
|
|
@@ -109,7 +113,7 @@ class AdminController extends Controller {
|
|
|
109
113
|
|
|
110
114
|
item = await this.afterCreate(item, req.user);
|
|
111
115
|
|
|
112
|
-
return res.success(item, this.
|
|
116
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
113
117
|
},
|
|
114
118
|
],
|
|
115
119
|
};
|
|
@@ -125,11 +129,12 @@ class AdminController extends Controller {
|
|
|
125
129
|
|
|
126
130
|
putModifyPublic() {
|
|
127
131
|
return {
|
|
132
|
+
disabled: !this.roles.UPDATE,
|
|
128
133
|
path: '/:id',
|
|
129
134
|
method: [
|
|
130
|
-
adminRoleMiddleware([this.
|
|
135
|
+
adminRoleMiddleware([this.roles.UPDATE]),
|
|
131
136
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
132
|
-
validateMiddleware(REQUEST_TYPE.BODY, this.
|
|
137
|
+
validateMiddleware(REQUEST_TYPE.BODY, this.rulesModify),
|
|
133
138
|
async (req, res) => {
|
|
134
139
|
let item = await this.repository.findOneById(req.params.id);
|
|
135
140
|
if (!item) return res.error(NOT_EXISTS);
|
|
@@ -140,7 +145,7 @@ class AdminController extends Controller {
|
|
|
140
145
|
|
|
141
146
|
item = await this.afterModify(item, req.user);
|
|
142
147
|
|
|
143
|
-
return res.success(item, this.
|
|
148
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
144
149
|
},
|
|
145
150
|
],
|
|
146
151
|
};
|
|
@@ -148,9 +153,10 @@ class AdminController extends Controller {
|
|
|
148
153
|
|
|
149
154
|
deletePublic() {
|
|
150
155
|
return {
|
|
156
|
+
disabled: !this.roles.DELETE,
|
|
151
157
|
path: '/:id',
|
|
152
158
|
method: [
|
|
153
|
-
adminRoleMiddleware([this.
|
|
159
|
+
adminRoleMiddleware([this.roles.DELETE]),
|
|
154
160
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
155
161
|
async (req, res) => {
|
|
156
162
|
const item = await this.repository.findOneById(req.params.id);
|
|
@@ -165,9 +171,10 @@ class AdminController extends Controller {
|
|
|
165
171
|
|
|
166
172
|
postRestoreTrash() {
|
|
167
173
|
return {
|
|
174
|
+
disabled: !this.roles.RESTORE,
|
|
168
175
|
path: '/:id',
|
|
169
176
|
method: [
|
|
170
|
-
adminRoleMiddleware([this.
|
|
177
|
+
adminRoleMiddleware([this.roles.RESTORE]),
|
|
171
178
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
172
179
|
async (req, res) => {
|
|
173
180
|
const item = await this.repository.findOneTrashById(req.params.id);
|
|
@@ -182,9 +189,10 @@ class AdminController extends Controller {
|
|
|
182
189
|
|
|
183
190
|
deleteDestroyTrash() {
|
|
184
191
|
return {
|
|
192
|
+
disabled: !this.roles.DESTROY,
|
|
185
193
|
path: '/:id',
|
|
186
194
|
method: [
|
|
187
|
-
adminRoleMiddleware([this.
|
|
195
|
+
adminRoleMiddleware([this.roles.DESTROY]),
|
|
188
196
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
189
197
|
async (req, res) => {
|
|
190
198
|
const item = await this.repository.findOneTrashById(req.params.id);
|
|
@@ -196,6 +204,34 @@ class AdminController extends Controller {
|
|
|
196
204
|
],
|
|
197
205
|
};
|
|
198
206
|
}
|
|
207
|
+
|
|
208
|
+
postImportSheet() {
|
|
209
|
+
return {
|
|
210
|
+
disabled: !this.roles.CREATE,
|
|
211
|
+
path: '/',
|
|
212
|
+
method: [
|
|
213
|
+
adminRoleMiddleware([this.roles.CREATE]),
|
|
214
|
+
verifyGoogleAppMiddleware(),
|
|
215
|
+
async (req, res) => {
|
|
216
|
+
const item = await this.repository.findOneTrashById(req.params.id);
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
postExportSheet() {
|
|
223
|
+
return {
|
|
224
|
+
disabled: !this.roles.READ,
|
|
225
|
+
path: '/',
|
|
226
|
+
method: [
|
|
227
|
+
adminRoleMiddleware([this.roles.READ]),
|
|
228
|
+
verifyGoogleAppMiddleware(),
|
|
229
|
+
async (req, res) => {
|
|
230
|
+
const item = await this.repository.findOneTrashById(req.params.id);
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
199
235
|
}
|
|
200
236
|
|
|
201
237
|
export default AdminController;
|
package/src/Controller.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
class Controller {
|
|
2
|
-
constructor(pathName = '', repository = null
|
|
2
|
+
constructor(pathName = '', repository = null) {
|
|
3
3
|
this.pathName = pathName;
|
|
4
4
|
this.repository = repository;
|
|
5
|
-
|
|
6
|
-
this.options = {
|
|
7
|
-
...options,
|
|
8
|
-
};
|
|
9
5
|
}
|
|
10
6
|
|
|
11
7
|
publicRouter() {
|
package/src/Server.js
CHANGED
|
@@ -254,30 +254,32 @@ class Server {
|
|
|
254
254
|
|
|
255
255
|
const msg = [];
|
|
256
256
|
_.map(this.controllers, (data) => {
|
|
257
|
-
const controller = data
|
|
257
|
+
const {controller} = data;
|
|
258
258
|
const controllerName = data.name;
|
|
259
259
|
const controllerVersion = data.version;
|
|
260
260
|
|
|
261
261
|
const listPublicRouter = controller.publicRouter();
|
|
262
262
|
|
|
263
263
|
_.map(listPublicRouter, (method) => {
|
|
264
|
-
const {name, type} = method;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
264
|
+
const {name, type, disabled} = method;
|
|
265
|
+
|
|
266
|
+
if (!disabled) {
|
|
267
|
+
const router = controller[name]();
|
|
268
|
+
|
|
269
|
+
router.path = `/${method.path}/${router.path}`;
|
|
270
|
+
router.path = controller.pathName ? `/${controller.pathName}${router.path}` : router.path;
|
|
271
|
+
router.path = controllerVersion.startsWith('v') ? `/${controllerVersion}${router.path}` : router.path;
|
|
272
|
+
router.path = path.normalize(router.path);
|
|
273
|
+
|
|
274
|
+
msg.push({
|
|
275
|
+
controller: controllerName,
|
|
276
|
+
version: controllerVersion,
|
|
277
|
+
type,
|
|
278
|
+
method: name,
|
|
279
|
+
path: router.path,
|
|
280
|
+
});
|
|
281
|
+
app[type](router.path, ...router.method);
|
|
282
|
+
}
|
|
281
283
|
});
|
|
282
284
|
});
|
|
283
285
|
|