Total Complexity | 4 |
Complexity/F | 1 |
Lines of Code | 44 |
Function Count | 4 |
Duplicated Lines | 44 |
Ratio | 100 % |
Changes | 0 |
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') |
|
|
|||
2 | const config = require('../../../config/config') |
||
3 | const ModelBase = require('../../model/base') |
||
4 | const ApiError = require('../../util/api_error') |
||
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 | } |