@azteam/express 1.2.176 → 1.2.177
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 +86 -107
package/package.json
CHANGED
package/src/AdminController.js
CHANGED
|
@@ -28,66 +28,57 @@ class AdminController extends Controller {
|
|
|
28
28
|
this.rulesModify = options.rulesModify || {};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
methodGetPaginatePublic = async (req, res) => {
|
|
32
|
+
const paginateData = await this.repository.find(req.query, req.paginate);
|
|
33
|
+
return res.success(paginateData, this.guardResponse, this.allowResponse);
|
|
34
|
+
};
|
|
35
|
+
|
|
31
36
|
getPaginatePublic() {
|
|
32
37
|
return {
|
|
33
38
|
disabled: !this.roles.READ,
|
|
34
39
|
path: '/',
|
|
35
|
-
method: [
|
|
36
|
-
adminRoleMiddleware([this.roles.READ]),
|
|
37
|
-
paginateMiddleware(this.paginateOptions),
|
|
38
|
-
async (req, res) => {
|
|
39
|
-
const paginateData = await this.repository.find(req.query, req.paginate);
|
|
40
|
-
return res.success(paginateData, this.guardResponse, this.allowResponse);
|
|
41
|
-
},
|
|
42
|
-
],
|
|
40
|
+
method: [adminRoleMiddleware([this.roles.READ]), paginateMiddleware(this.paginateOptions), this.methodGetPaginatePublic],
|
|
43
41
|
};
|
|
44
42
|
}
|
|
45
43
|
|
|
44
|
+
methodGetPaginateTrash = async (req, res) => {
|
|
45
|
+
const paginateData = await this.repository.findTrash(req.query, req.paginate);
|
|
46
|
+
return res.success(paginateData, this.guardResponse, this.allowResponse);
|
|
47
|
+
};
|
|
48
|
+
|
|
46
49
|
getPaginateTrash() {
|
|
47
50
|
return {
|
|
48
51
|
disabled: !this.roles.READ,
|
|
49
52
|
path: '/',
|
|
50
|
-
method: [
|
|
51
|
-
adminRoleMiddleware([this.roles.READ]),
|
|
52
|
-
paginateMiddleware(this.paginateOptions),
|
|
53
|
-
async (req, res) => {
|
|
54
|
-
const paginateData = await this.repository.findTrash(req.query, req.paginate);
|
|
55
|
-
|
|
56
|
-
return res.success(paginateData, this.guardResponse, this.allowResponse);
|
|
57
|
-
},
|
|
58
|
-
],
|
|
53
|
+
method: [adminRoleMiddleware([this.roles.READ]), paginateMiddleware(this.paginateOptions), this.methodGetPaginateTrash],
|
|
59
54
|
};
|
|
60
55
|
}
|
|
61
56
|
|
|
57
|
+
methodGetOnePublic = async (req, res) => {
|
|
58
|
+
const item = await this.repository.findOneById(req.params.id);
|
|
59
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
60
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
61
|
+
};
|
|
62
|
+
|
|
62
63
|
getOnePublic() {
|
|
63
64
|
return {
|
|
64
65
|
disabled: !this.roles.READ,
|
|
65
66
|
path: '/:id',
|
|
66
|
-
method: [
|
|
67
|
-
adminRoleMiddleware([this.roles.READ]),
|
|
68
|
-
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
69
|
-
async (req, res) => {
|
|
70
|
-
const item = await this.repository.findOneById(req.params.id);
|
|
71
|
-
if (!item) return res.error(NOT_EXISTS);
|
|
72
|
-
return res.success(item, this.guardResponse, this.allowResponse);
|
|
73
|
-
},
|
|
74
|
-
],
|
|
67
|
+
method: [adminRoleMiddleware([this.roles.READ]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodGetOnePublic],
|
|
75
68
|
};
|
|
76
69
|
}
|
|
77
70
|
|
|
71
|
+
methodGetOneTrash = async (req, res) => {
|
|
72
|
+
const item = await this.repository.findOneTrashById(req.params.id);
|
|
73
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
74
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
75
|
+
};
|
|
76
|
+
|
|
78
77
|
getOneTrash() {
|
|
79
78
|
return {
|
|
80
79
|
disabled: !this.roles.READ,
|
|
81
80
|
path: '/:id',
|
|
82
|
-
method: [
|
|
83
|
-
adminRoleMiddleware([this.roles.READ]),
|
|
84
|
-
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
85
|
-
async (req, res) => {
|
|
86
|
-
const item = await this.repository.findOneTrashById(req.params.id);
|
|
87
|
-
if (!item) return res.error(NOT_EXISTS);
|
|
88
|
-
return res.success(item, this.guardResponse, this.allowResponse);
|
|
89
|
-
},
|
|
90
|
-
],
|
|
81
|
+
method: [adminRoleMiddleware([this.roles.READ]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodGetOneTrash],
|
|
91
82
|
};
|
|
92
83
|
}
|
|
93
84
|
|
|
@@ -99,23 +90,21 @@ class AdminController extends Controller {
|
|
|
99
90
|
return item;
|
|
100
91
|
}
|
|
101
92
|
|
|
93
|
+
methodPostCreatePublic = async (req, res) => {
|
|
94
|
+
const data = await this.beforeCreate(req.body, req.user);
|
|
95
|
+
|
|
96
|
+
let item = await this.repository.createByUser(req.user.id, data);
|
|
97
|
+
|
|
98
|
+
item = await this.afterCreate(item, req.user);
|
|
99
|
+
|
|
100
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
101
|
+
};
|
|
102
|
+
|
|
102
103
|
postCreatePublic() {
|
|
103
104
|
return {
|
|
104
105
|
disabled: !this.roles.CREATE,
|
|
105
106
|
path: '/',
|
|
106
|
-
method: [
|
|
107
|
-
adminRoleMiddleware([this.roles.CREATE]),
|
|
108
|
-
validateMiddleware(REQUEST_TYPE.BODY, this.rulesCreate),
|
|
109
|
-
async (req, res) => {
|
|
110
|
-
const data = await this.beforeCreate(req.body, req.user);
|
|
111
|
-
|
|
112
|
-
let item = await this.repository.createByUser(req.user.id, data);
|
|
113
|
-
|
|
114
|
-
item = await this.afterCreate(item, req.user);
|
|
115
|
-
|
|
116
|
-
return res.success(item, this.guardResponse, this.allowResponse);
|
|
117
|
-
},
|
|
118
|
-
],
|
|
107
|
+
method: [adminRoleMiddleware([this.roles.CREATE]), validateMiddleware(REQUEST_TYPE.BODY, this.rulesCreate), this.methodPostCreatePublic],
|
|
119
108
|
};
|
|
120
109
|
}
|
|
121
110
|
|
|
@@ -127,6 +116,19 @@ class AdminController extends Controller {
|
|
|
127
116
|
return item;
|
|
128
117
|
}
|
|
129
118
|
|
|
119
|
+
methodPutModifyPublic = async (req, res) => {
|
|
120
|
+
let item = await this.repository.findOneById(req.params.id);
|
|
121
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
122
|
+
|
|
123
|
+
const data = await this.beforeModify(req.body, req.user);
|
|
124
|
+
|
|
125
|
+
item = await this.repository.modifyByUser(req.user.id, item, data);
|
|
126
|
+
|
|
127
|
+
item = await this.afterModify(item, req.user);
|
|
128
|
+
|
|
129
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
130
|
+
};
|
|
131
|
+
|
|
130
132
|
putModifyPublic() {
|
|
131
133
|
return {
|
|
132
134
|
disabled: !this.roles.UPDATE,
|
|
@@ -135,101 +137,78 @@ class AdminController extends Controller {
|
|
|
135
137
|
adminRoleMiddleware([this.roles.UPDATE]),
|
|
136
138
|
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
137
139
|
validateMiddleware(REQUEST_TYPE.BODY, this.rulesModify),
|
|
138
|
-
|
|
139
|
-
let item = await this.repository.findOneById(req.params.id);
|
|
140
|
-
if (!item) return res.error(NOT_EXISTS);
|
|
141
|
-
|
|
142
|
-
const data = await this.beforeModify(req.body, req.user);
|
|
143
|
-
|
|
144
|
-
item = await this.repository.modifyByUser(req.user.id, item, data);
|
|
145
|
-
|
|
146
|
-
item = await this.afterModify(item, req.user);
|
|
147
|
-
|
|
148
|
-
return res.success(item, this.guardResponse, this.allowResponse);
|
|
149
|
-
},
|
|
140
|
+
this.methodPutModifyPublic,
|
|
150
141
|
],
|
|
151
142
|
};
|
|
152
143
|
}
|
|
153
144
|
|
|
145
|
+
methodDeletePublic = async (req, res) => {
|
|
146
|
+
const item = await this.repository.findOneById(req.params.id);
|
|
147
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
148
|
+
|
|
149
|
+
await this.repository.deleteByUser(req.user.id, item);
|
|
150
|
+
return res.success(true);
|
|
151
|
+
};
|
|
152
|
+
|
|
154
153
|
deletePublic() {
|
|
155
154
|
return {
|
|
156
155
|
disabled: !this.roles.DELETE,
|
|
157
156
|
path: '/:id',
|
|
158
|
-
method: [
|
|
159
|
-
adminRoleMiddleware([this.roles.DELETE]),
|
|
160
|
-
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
161
|
-
async (req, res) => {
|
|
162
|
-
const item = await this.repository.findOneById(req.params.id);
|
|
163
|
-
if (!item) return res.error(NOT_EXISTS);
|
|
164
|
-
|
|
165
|
-
await this.repository.deleteByUser(req.user.id, item);
|
|
166
|
-
return res.success(true);
|
|
167
|
-
},
|
|
168
|
-
],
|
|
157
|
+
method: [adminRoleMiddleware([this.roles.DELETE]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodDeletePublic],
|
|
169
158
|
};
|
|
170
159
|
}
|
|
171
160
|
|
|
161
|
+
methodPostRestoreTrash = async (req, res) => {
|
|
162
|
+
const item = await this.repository.findOneTrashById(req.params.id);
|
|
163
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
164
|
+
|
|
165
|
+
await this.repository.restoreByUser(req.user.id, item);
|
|
166
|
+
return res.success(true);
|
|
167
|
+
};
|
|
168
|
+
|
|
172
169
|
postRestoreTrash() {
|
|
173
170
|
return {
|
|
174
171
|
disabled: !this.roles.RESTORE,
|
|
175
172
|
path: '/:id',
|
|
176
|
-
method: [
|
|
177
|
-
adminRoleMiddleware([this.roles.RESTORE]),
|
|
178
|
-
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
179
|
-
async (req, res) => {
|
|
180
|
-
const item = await this.repository.findOneTrashById(req.params.id);
|
|
181
|
-
if (!item) return res.error(NOT_EXISTS);
|
|
182
|
-
|
|
183
|
-
await this.repository.restoreByUser(req.user.id, item);
|
|
184
|
-
return res.success(true);
|
|
185
|
-
},
|
|
186
|
-
],
|
|
173
|
+
method: [adminRoleMiddleware([this.roles.RESTORE]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodPostRestoreTrash],
|
|
187
174
|
};
|
|
188
175
|
}
|
|
189
176
|
|
|
177
|
+
methodDeleteDestroyTrash = async (req, res) => {
|
|
178
|
+
const item = await this.repository.findOneTrashById(req.params.id);
|
|
179
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
180
|
+
|
|
181
|
+
await this.repository.destroy(item);
|
|
182
|
+
return res.success(true);
|
|
183
|
+
};
|
|
184
|
+
|
|
190
185
|
deleteDestroyTrash() {
|
|
191
186
|
return {
|
|
192
187
|
disabled: !this.roles.DESTROY,
|
|
193
188
|
path: '/:id',
|
|
194
|
-
method: [
|
|
195
|
-
adminRoleMiddleware([this.roles.DESTROY]),
|
|
196
|
-
validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
|
|
197
|
-
async (req, res) => {
|
|
198
|
-
const item = await this.repository.findOneTrashById(req.params.id);
|
|
199
|
-
if (!item) return res.error(NOT_EXISTS);
|
|
200
|
-
|
|
201
|
-
await this.repository.destroy(item);
|
|
202
|
-
return res.success(true);
|
|
203
|
-
},
|
|
204
|
-
],
|
|
189
|
+
method: [adminRoleMiddleware([this.roles.DESTROY]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodDeleteDestroyTrash],
|
|
205
190
|
};
|
|
206
191
|
}
|
|
207
192
|
|
|
193
|
+
methodDPostImportSheet = async (req, res) => {
|
|
194
|
+
return res.success(true);
|
|
195
|
+
};
|
|
208
196
|
postImportSheet() {
|
|
209
197
|
return {
|
|
210
198
|
disabled: !this.roles.CREATE,
|
|
211
199
|
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
|
-
],
|
|
200
|
+
method: [adminRoleMiddleware([this.roles.CREATE]), verifyGoogleAppMiddleware(), this.methodDPostImportSheet],
|
|
219
201
|
};
|
|
220
202
|
}
|
|
221
203
|
|
|
204
|
+
methodPostExportSheet = async (req, res) => {
|
|
205
|
+
return res.success(true);
|
|
206
|
+
};
|
|
222
207
|
postExportSheet() {
|
|
223
208
|
return {
|
|
224
209
|
disabled: !this.roles.READ,
|
|
225
210
|
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
|
-
],
|
|
211
|
+
method: [adminRoleMiddleware([this.roles.READ]), verifyGoogleAppMiddleware(), this.methodPostExportSheet],
|
|
233
212
|
};
|
|
234
213
|
}
|
|
235
214
|
}
|