@azteam/express 1.2.120 → 1.2.121
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/AdminController.js +27 -27
package/package.json
CHANGED
package/src/AdminController.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {NOT_EXISTS} from '@azteam/error';
|
|
1
|
+
import { NOT_EXISTS } from '@azteam/error';
|
|
2
2
|
|
|
3
|
-
import {REQUEST_TYPE, USER_LEVEL} from './constant';
|
|
4
|
-
import {paginateMiddleware, roleMiddleware, validateMiddleware} from './middleware';
|
|
5
|
-
import {rulesID} from './validate';
|
|
3
|
+
import { REQUEST_TYPE, USER_LEVEL } from './constant';
|
|
4
|
+
import { paginateMiddleware, roleMiddleware, validateMiddleware } from './middleware';
|
|
5
|
+
import { rulesID } from './validate';
|
|
6
6
|
import Controller from './Controller';
|
|
7
7
|
|
|
8
8
|
|
|
@@ -34,14 +34,14 @@ class AdminController extends Controller {
|
|
|
34
34
|
method: [
|
|
35
35
|
roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
|
|
36
36
|
paginateMiddleware(this.options.paginateOptions),
|
|
37
|
-
async
|
|
37
|
+
async (req, res) => {
|
|
38
38
|
const paginateData = await this.repository.find(req.query, req.paginate);
|
|
39
39
|
|
|
40
40
|
return res.success(paginateData, this.options.guardResponse, this.options.allowResponse);
|
|
41
41
|
}
|
|
42
42
|
]
|
|
43
43
|
};
|
|
44
|
-
}
|
|
44
|
+
};
|
|
45
45
|
|
|
46
46
|
getPaginateTrash() {
|
|
47
47
|
return {
|
|
@@ -49,14 +49,14 @@ class AdminController extends Controller {
|
|
|
49
49
|
method: [
|
|
50
50
|
roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
|
|
51
51
|
paginateMiddleware(this.options.paginateOptions),
|
|
52
|
-
async
|
|
52
|
+
async (req, res) => {
|
|
53
53
|
const paginateData = await this.repository.findTrash(req.query, req.paginate);
|
|
54
54
|
|
|
55
55
|
return res.success(paginateData, this.options.guardResponse, this.options.allowResponse);
|
|
56
56
|
}
|
|
57
57
|
]
|
|
58
58
|
};
|
|
59
|
-
}
|
|
59
|
+
};
|
|
60
60
|
|
|
61
61
|
getOne() {
|
|
62
62
|
return {
|
|
@@ -64,7 +64,7 @@ class AdminController extends Controller {
|
|
|
64
64
|
method: [
|
|
65
65
|
roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
|
|
66
66
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
67
|
-
async
|
|
67
|
+
async (req, res) => {
|
|
68
68
|
const item = await this.repository.findOneById(req.params.id);
|
|
69
69
|
if (!item) return res.error(NOT_EXISTS);
|
|
70
70
|
return res.success(item, this.options.guardResponse, this.options.allowResponse);
|
|
@@ -72,7 +72,7 @@ class AdminController extends Controller {
|
|
|
72
72
|
]
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
}
|
|
75
|
+
};
|
|
76
76
|
|
|
77
77
|
getOneTrash() {
|
|
78
78
|
return {
|
|
@@ -80,7 +80,7 @@ class AdminController extends Controller {
|
|
|
80
80
|
method: [
|
|
81
81
|
roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
|
|
82
82
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
83
|
-
async
|
|
83
|
+
async (req, res) => {
|
|
84
84
|
const item = await this.repository.findOneTrashById(req.params.id);
|
|
85
85
|
if (!item) return res.error(NOT_EXISTS);
|
|
86
86
|
return res.success(item, this.options.guardResponse, this.options.allowResponse);
|
|
@@ -88,12 +88,12 @@ class AdminController extends Controller {
|
|
|
88
88
|
]
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
}
|
|
91
|
+
};
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
beforeCreate(data) {
|
|
94
|
+
async beforeCreate(data, user) {
|
|
95
95
|
return data;
|
|
96
|
-
}
|
|
96
|
+
};
|
|
97
97
|
|
|
98
98
|
postCreate() {
|
|
99
99
|
return {
|
|
@@ -101,9 +101,9 @@ class AdminController extends Controller {
|
|
|
101
101
|
method: [
|
|
102
102
|
roleMiddleware([this.options.roles.CREATE], USER_LEVEL.ADMIN),
|
|
103
103
|
validateMiddleware(REQUEST_TYPE.BODY, this.options.rulesCreate),
|
|
104
|
-
async
|
|
104
|
+
async (req, res) => {
|
|
105
105
|
|
|
106
|
-
const data = this.beforeCreate(req.body);
|
|
106
|
+
const data = await this.beforeCreate(req.body, req.user);
|
|
107
107
|
|
|
108
108
|
const item = await this.repository.createByUser(req.user.id, data);
|
|
109
109
|
|
|
@@ -111,12 +111,12 @@ class AdminController extends Controller {
|
|
|
111
111
|
}
|
|
112
112
|
]
|
|
113
113
|
};
|
|
114
|
-
}
|
|
114
|
+
};
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
beforeModify(item) {
|
|
117
|
+
async beforeModify(item, user) {
|
|
118
118
|
return item;
|
|
119
|
-
}
|
|
119
|
+
};
|
|
120
120
|
|
|
121
121
|
putModify() {
|
|
122
122
|
return {
|
|
@@ -125,12 +125,12 @@ class AdminController extends Controller {
|
|
|
125
125
|
roleMiddleware([this.options.roles.UPDATE], USER_LEVEL.ADMIN),
|
|
126
126
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
127
127
|
validateMiddleware(REQUEST_TYPE.BODY, this.options.rulesModify),
|
|
128
|
-
async
|
|
128
|
+
async (req, res) => {
|
|
129
129
|
|
|
130
130
|
let item = await this.options.roles.findOneById(req.params.id);
|
|
131
131
|
if (!item) return res.error(NOT_EXISTS);
|
|
132
132
|
|
|
133
|
-
item = await this.beforeModify(item);
|
|
133
|
+
item = await this.beforeModify(item, req.user);
|
|
134
134
|
|
|
135
135
|
item = await this.options.roles.modifyByUser(req.user.id, item, req.body);
|
|
136
136
|
|
|
@@ -138,7 +138,7 @@ class AdminController extends Controller {
|
|
|
138
138
|
}
|
|
139
139
|
]
|
|
140
140
|
};
|
|
141
|
-
}
|
|
141
|
+
};
|
|
142
142
|
|
|
143
143
|
delete() {
|
|
144
144
|
return {
|
|
@@ -146,7 +146,7 @@ class AdminController extends Controller {
|
|
|
146
146
|
method: [
|
|
147
147
|
roleMiddleware([this.options.roles.DELETE], USER_LEVEL.ADMIN),
|
|
148
148
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
149
|
-
async
|
|
149
|
+
async (req, res) => {
|
|
150
150
|
const item = await this.repository.findOneById(req.params.id);
|
|
151
151
|
if (!item) return res.error(NOT_EXISTS);
|
|
152
152
|
|
|
@@ -155,7 +155,7 @@ class AdminController extends Controller {
|
|
|
155
155
|
}
|
|
156
156
|
]
|
|
157
157
|
};
|
|
158
|
-
}
|
|
158
|
+
};
|
|
159
159
|
|
|
160
160
|
postRestore() {
|
|
161
161
|
return {
|
|
@@ -163,7 +163,7 @@ class AdminController extends Controller {
|
|
|
163
163
|
method: [
|
|
164
164
|
roleMiddleware([this.options.roles.RESTORE], USER_LEVEL.ADMIN),
|
|
165
165
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
166
|
-
async
|
|
166
|
+
async (req, res) => {
|
|
167
167
|
const item = await this.repository.findOneTrashById(req.params.id);
|
|
168
168
|
if (!item) return res.error(NOT_EXISTS);
|
|
169
169
|
|
|
@@ -172,7 +172,7 @@ class AdminController extends Controller {
|
|
|
172
172
|
}
|
|
173
173
|
]
|
|
174
174
|
};
|
|
175
|
-
}
|
|
175
|
+
};
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
export default AdminController;
|
|
178
|
+
export default AdminController;
|