app/model/users.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 45
Function Count 4

Duplication

Duplicated Lines 45
Ratio 100 %

Importance

Changes 0
Metric Value
cc 0
wmc 4
eloc 22
c 0
b 0
f 0
nc 1
mnd 0
bc 4
fnc 4
dl 45
loc 45
rs 10
bpm 1
cpm 1
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A module.exports.getUserByOpenId 11 11 1
A module.exports.getUser 11 11 1
A module.exports.addUser 5 5 1
A module.exports.editUser 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 View Code Duplication
const DB = require('../libraries/db')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
const ModelBase = require('./base')
3
4
let table = 'fc_users'
5
6
7
module.exports = {
8
9
	getUserByOpenId: async function (openid) {
10
11
		let user = DB.readMysql.first(
12
			'*'
13
		)
14
			.from(table)
15
			.where('openid', openid)
16
17
		return await user
18
19
	},
20
21
	getUser: async function (uid) {
22
23
		let user = DB.readMysql.first(
24
			'*'
25
		)
26
			.from(table)
27
			.where('id', uid)
28
29
		return await user
30
31
	},
32
33
	addUser: async function (data) {
34
		let result = await ModelBase.execInsert(table, data)
35
36
		return await result
37
	},
38
39
	editUser: async function (data, where, notWhere = {}) {
40
		let result = await ModelBase.execUpdate(table, data, where, notWhere)
41
42
		return await result
43
	}
44
45
}