Passed
Push — master ( 1adf40...f067da )
by lv
01:05
created

module.exports.test   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 66
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 44
c 0
b 0
f 0
nc 3
dl 0
loc 66
rs 8.824
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
const Response = require('../util/response')
2
const Validate = require('../util/validate')
3
const Uuid = require('../util/uuid')
4
const ModelUser = require('../model/users')
5
const Redis = require('../libraries/redis')
6
7
module.exports = {
8
9
	test: async function (ctx) {
10
11
		console.log('controller input')
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
12
		console.log(ctx.input)
13
		console.log(ctx.params)
14
15
		let conflict = []
16
		let tmpNo = 'none'
17
		let orderNo = []
18
		for (let index = 0; index < 100; index++) {
19
			let genNo = await Uuid.genOrderNo()
20
			orderNo[index] = genNo
21
			if (genNo === tmpNo) {
22
				conflict.push(genNo)
23
			}
24
			tmpNo = genNo
25
		}
26
		orderNo.reverse()
27
28
		let orderResult = {
29
			"conflict": conflict,
30
			"order": orderNo
31
		}
32
33
		let rules = {
34
			'uid': 'numeric|in:"0","3","4"',
35
			'filter': 'in:1,2,3',
36
		}
37
38
		let message = {
39
			'uid.required': 'kkkk',
40
			'uid.numeric': '数字数字',
41
			'uid.in': 'uid 必须在xxx范围内'
42
		}
43
44
		Validate(ctx, rules, message)
45
46
		Redis.set('testkey', JSON.stringify(message))
47
		Redis.expire('testkey', 86400 * 30)
48
49
		let insertData = [
0 ignored issues
show
Unused Code introduced by
The variable insertData seems to be never used. Consider removing it.
Loading history...
50
			{
51
				'name': 'te',
52
				'user_id': 1,
53
				'description': 'uni * 2'
54
			},
55
			{
56
				'name': 'test2',
57
				'user_id': 2,
58
				'description': 'test2'
59
			},
0 ignored issues
show
Bug introduced by
The variable seems to be never declared. If this is a global, consider adding a /** global: */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
60
		]
61
62
		let sigleData = {
0 ignored issues
show
Unused Code introduced by
The variable sigleData seems to be never used. Consider removing it.
Loading history...
63
			'name': '测试',
64
			'user_id': 2,
65
			'description': 'test4'
66
		}
67
68
		let realInsertData = {
0 ignored issues
show
Unused Code introduced by
The variable realInsertData seems to be never used. Consider removing it.
Loading history...
69
			'openid': 'test' + new Date().getTime()
70
		}
71
		// insertData = await ModelUser.addUser(realInsertData)
72
73
		return Response.output(ctx, orderResult)
74
	},
75
76
	edit: async function (ctx) {
77
		console.log(ctx.params)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
78
		let updateData = {
79
			'name': '更新',
80
			'description': '更新测试'
81
		}
82
83
		let where = {
84
			'user_id': 2,
85
			'name': ['test', 'test2', 'test3']
86
		}
87
88
		let notWhere = {
89
			'description': ['test4', 'test3']
90
		}
91
92
		let data = await ModelUser.editUser(updateData, where, notWhere)
93
94
		return Response.output(ctx, data)
95
	},
96
97
}