| Total Complexity | 4 |
| Complexity/F | 1 |
| Lines of Code | 42 |
| Function Count | 4 |
| Duplicated Lines | 42 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | |||
| 4 | const table = 'mist_store' |
||
| 5 | |||
| 6 | module.exports = { |
||
| 7 | add: async function (data) { |
||
| 8 | let res = await ModelBase.execInsert(table, data) |
||
| 9 | return res; |
||
| 10 | }, |
||
| 11 | |||
| 12 | first: async function (id) { |
||
| 13 | |||
| 14 | let result = DB.readMysql.first( |
||
| 15 | '*' |
||
| 16 | ) |
||
| 17 | .from(table) |
||
| 18 | .where('id', id) |
||
| 19 | |||
| 20 | return await result |
||
| 21 | |||
| 22 | }, |
||
| 23 | |||
| 24 | getSellerStores: async function (sellerId) { |
||
| 25 | |||
| 26 | let result = DB.readMysql.select( |
||
| 27 | '*' |
||
| 28 | ) |
||
| 29 | .from(table) |
||
| 30 | .where('seller_id', sellerId) |
||
| 31 | |||
| 32 | return await result |
||
| 33 | |||
| 34 | }, |
||
| 35 | |||
| 36 | edit: async function (data, where, notWhere = {}) { |
||
| 37 | let result = ModelBase.execUpdate(table, data, where, notWhere) |
||
| 38 | |||
| 39 | return await result |
||
| 40 | } |
||
| 41 | |||
| 42 | } |