@azteam/express 1.2.219 → 1.2.222
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
CHANGED
package/src/AdminController.js
CHANGED
|
@@ -109,11 +109,11 @@ class AdminController extends Controller {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
async beforeCreate(data
|
|
112
|
+
async beforeCreate(data) {
|
|
113
113
|
return data;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
async afterCreate(item
|
|
116
|
+
async afterCreate(item) {
|
|
117
117
|
return item;
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -135,11 +135,11 @@ class AdminController extends Controller {
|
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
async beforeModify(data
|
|
138
|
+
async beforeModify(data) {
|
|
139
139
|
return data;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
async afterModify(item
|
|
142
|
+
async afterModify(item) {
|
|
143
143
|
return item;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -147,9 +147,9 @@ class AdminController extends Controller {
|
|
|
147
147
|
let item = await this.repository.findOneById(req.params.id);
|
|
148
148
|
if (!item) return res.error(NOT_EXISTS);
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
item.loadData(req.body);
|
|
151
|
+
item.modified_id = req.user.id;
|
|
152
|
+
await item.save();
|
|
153
153
|
|
|
154
154
|
item = await this.afterModify(item, req.user);
|
|
155
155
|
|
|
@@ -169,11 +169,50 @@ class AdminController extends Controller {
|
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
putModifyStatusAvailablePublic() {
|
|
173
|
+
return {
|
|
174
|
+
disabled: !this.roles.UPDATE,
|
|
175
|
+
path: '/available/:id',
|
|
176
|
+
method: [
|
|
177
|
+
adminRoleMiddleware([this.roles.UPDATE]),
|
|
178
|
+
validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
|
|
179
|
+
async (req, res) => {
|
|
180
|
+
const item = await this.repository.findOneById(req.params.id);
|
|
181
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
182
|
+
|
|
183
|
+
await item.modifyStatusAvailable(req.user.id);
|
|
184
|
+
|
|
185
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
putModifyStatusUnavailablePublic() {
|
|
192
|
+
return {
|
|
193
|
+
disabled: !this.roles.UPDATE,
|
|
194
|
+
path: '/unavailable/:id',
|
|
195
|
+
method: [
|
|
196
|
+
adminRoleMiddleware([this.roles.UPDATE]),
|
|
197
|
+
validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
|
|
198
|
+
async (req, res) => {
|
|
199
|
+
const item = await this.repository.findOneById(req.params.id);
|
|
200
|
+
if (!item) return res.error(NOT_EXISTS);
|
|
201
|
+
|
|
202
|
+
await item.modifyStatusUnavailable(req.user.id);
|
|
203
|
+
|
|
204
|
+
return res.success(item, this.guardResponse, this.allowResponse);
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
172
210
|
methodDeletePublic = async (req, res) => {
|
|
173
211
|
const item = await this.repository.findOneById(req.params.id);
|
|
174
212
|
if (!item) return res.error(NOT_EXISTS);
|
|
175
213
|
|
|
176
|
-
await
|
|
214
|
+
await item.delete(req.user.id);
|
|
215
|
+
|
|
177
216
|
return res.success(true);
|
|
178
217
|
};
|
|
179
218
|
|
|
@@ -189,7 +228,8 @@ class AdminController extends Controller {
|
|
|
189
228
|
const item = await this.repository.findOneTrashById(req.params.id);
|
|
190
229
|
if (!item) return res.error(NOT_EXISTS);
|
|
191
230
|
|
|
192
|
-
await
|
|
231
|
+
await item.restore(req.user.id);
|
|
232
|
+
|
|
193
233
|
return res.success(true);
|
|
194
234
|
};
|
|
195
235
|
|
|
@@ -205,7 +245,8 @@ class AdminController extends Controller {
|
|
|
205
245
|
const item = await this.repository.findOneTrashById(req.params.id);
|
|
206
246
|
if (!item) return res.error(NOT_EXISTS);
|
|
207
247
|
|
|
208
|
-
await this.repository.destroy(item);
|
|
248
|
+
await this.repository.destroy(item.id);
|
|
249
|
+
|
|
209
250
|
return res.success(true);
|
|
210
251
|
};
|
|
211
252
|
|
|
@@ -14,7 +14,7 @@ export default function (key, options = {}) {
|
|
|
14
14
|
let cacheKey = key;
|
|
15
15
|
|
|
16
16
|
if (options.query) {
|
|
17
|
-
cacheKey
|
|
17
|
+
cacheKey = `${cacheKey}:${_.get(req, options.query)}`;
|
|
18
18
|
}
|
|
19
19
|
if (req.paginate) {
|
|
20
20
|
if (_.isEmpty(req.query) && req.paginate.page <= options.limitPage) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
|
|
3
3
|
function omitData(data) {
|
|
4
|
-
Object.keys(data).map(function (key
|
|
4
|
+
Object.keys(data).map(function (key) {
|
|
5
5
|
let value = data[key];
|
|
6
6
|
if (typeof value === 'string') {
|
|
7
7
|
value = value.trim();
|
|
@@ -10,11 +10,10 @@ function omitData(data) {
|
|
|
10
10
|
} else {
|
|
11
11
|
data[key] = value;
|
|
12
12
|
}
|
|
13
|
-
} else {
|
|
14
|
-
|
|
15
|
-
delete data[key];
|
|
16
|
-
}
|
|
13
|
+
} else if (value === null || value === undefined || Number.isNaN(value)) {
|
|
14
|
+
delete data[key];
|
|
17
15
|
}
|
|
16
|
+
return true;
|
|
18
17
|
});
|
|
19
18
|
return data;
|
|
20
19
|
}
|