Conditions | 10 |
Paths | 256 |
Total Lines | 25 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Complex classes like module.exports.edit often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | const Response = require('../util/response') |
||
15 | edit: async function (ctx) { |
||
16 | console.log('--------- ctx-uid: --------' + ctx.uid) |
||
17 | console.log(ctx.input.nickname) |
||
18 | let updateData = {} |
||
19 | if (!!ctx.input.nickname) updateData.nickname = ctx.input.nickname |
||
20 | if (!!ctx.input.gender) updateData.gender = ctx.input.gender |
||
21 | if (!!ctx.input.avatar) updateData.avatar = ctx.input.avatar |
||
22 | if (!!ctx.input.country) updateData.country = ctx.input.country |
||
23 | if (!!ctx.input.province) updateData.province = ctx.input.province |
||
24 | if (!!ctx.input.city) updateData.city = ctx.input.city |
||
25 | if (!!ctx.input.mobile) updateData.mobile = ctx.input.mobile |
||
26 | if (!!ctx.input.language) updateData.language = ctx.input.language |
||
27 | |||
28 | let where = { |
||
29 | 'id': ctx.uid, |
||
30 | } |
||
31 | |||
32 | if (await General.isEmpty(updateData)) { |
||
33 | throw new ApiError('common.paramsEmpty', '更新内容') |
||
34 | } else { |
||
35 | let data = await ModelUser.editUser(updateData, where) |
||
36 | return Response.output(ctx, {}) |
||
37 | } |
||
38 | |||
39 | } |
||
40 | |||
41 | } |