app/model/catering/customer.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 44
Function Count 4

Duplication

Duplicated Lines 44
Ratio 100 %

Importance

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

4 Functions

Rating   Name   Duplication   Size   Complexity  
A module.exports.edit 5 5 1
A module.exports.getCustomerByOpenId 11 11 1
A module.exports.first 11 11 1
A module.exports.add 4 4 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 config = require('../../../config/config')
0 ignored issues
show
Unused Code introduced by
The constant config seems to be never used. Consider removing it.
Loading history...
3
const ModelBase = require('../../model/base')
4
const ApiError = require('../../util/api_error')
0 ignored issues
show
Unused Code introduced by
The constant ApiError seems to be never used. Consider removing it.
Loading history...
5
6
const table = 'mist_customer'
7
8
module.exports = {
9
    add: async function (data) {
10
        let res = await ModelBase.execInsert(table, data)
11
        return res;
12
    },
13
14
	getCustomerByOpenId: async function (openid) {
15
16
		let user = await DB.readMysql.first(
17
			'*'
18
		)
19
			.from(table)
20
			.where('openid', openid)
21
22
		return user
23
24
	},
25
26
	first: async function (customerId) {
27
28
		let user = await DB.readMysql.first(
29
			'*'
30
		)
31
			.from(table)
32
			.where('id', customerId)
33
34
		return user
35
36
	},
37
38
	edit: async function (data, where, notWhere = {}) {
39
		let result = await ModelBase.execUpdate(table, data, where, notWhere)
40
41
		return result
42
	}
43
44
}