| Total Complexity | 6 |
| Complexity/F | 1.5 |
| Lines of Code | 50 |
| Function Count | 4 |
| 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_product' |
||
| 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 | if (_.has(filter, 'category_id')) { |
||
| 25 | // todo |
||
| 26 | } |
||
| 27 | |||
| 28 | return await result |
||
| 29 | |||
| 30 | }, |
||
| 31 | |||
| 32 | first: async function (id) { |
||
| 33 | |||
| 34 | let result = DB.readMysql.first( |
||
| 35 | '*' |
||
| 36 | ) |
||
| 37 | .from(table) |
||
| 38 | .where('id', id) |
||
| 39 | |||
| 40 | return await result |
||
| 41 | |||
| 42 | }, |
||
| 43 | |||
| 44 | edit: async function (data, where, notWhere = {}) { |
||
| 45 | let result = ModelBase.execUpdate(table, data, where, notWhere) |
||
| 46 | |||
| 47 | return await result |
||
| 48 | } |
||
| 49 | |||
| 50 | } |
||
| 51 |