Total Complexity | 6 |
Complexity/F | 1.2 |
Lines of Code | 50 |
Function Count | 5 |
Duplicated Lines | 50 |
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 ModelBase = require('../../model/base') |
||
3 | const _ = require('underscore') |
||
4 | |||
5 | const table = 'mist_category' |
||
6 | |||
7 | module.exports = { |
||
8 | add: async function (data) { |
||
9 | let res = await ModelBase.execInsert(table, data) |
||
10 | return res; |
||
11 | }, |
||
12 | |||
13 | list: async function (storeId, filter = {}) { |
||
14 | |||
15 | let result = DB.readMysql.select( |
||
16 | '*' |
||
17 | ) |
||
18 | .from(table) |
||
19 | .where('store_id', storeId) |
||
20 | .whereNot('status', -1) |
||
21 | |||
22 | if (_.has(filter, 'status')) result.where('status', filter.status) |
||
23 | |||
24 | return await result |
||
25 | |||
26 | }, |
||
27 | |||
28 | first: async function (id) { |
||
29 | |||
30 | let result = await DB.readMysql.first( |
||
31 | '*' |
||
32 | ) |
||
33 | .from(table) |
||
34 | .where('id', id) |
||
35 | |||
36 | return result |
||
37 | |||
38 | }, |
||
39 | |||
40 | edit: async function (data, where, notWhere = {}) { |
||
41 | let result = await ModelBase.execUpdate(table, data, where, notWhere) |
||
42 | |||
43 | return result |
||
44 | }, |
||
45 | |||
46 | getMaxSort: async function (storeId) { |
||
47 | return await DB.readMysql.first('sort').from(table).where({ store_id: storeId }).orderBy('sort', 'DESC') |
||
48 | } |
||
49 | |||
50 | } |
||
51 |