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

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 50
Function Count 5

Duplication

Duplicated Lines 50
Ratio 100 %

Importance

Changes 0
Metric Value
cc 0
wmc 6
eloc 27
c 0
b 0
f 0
nc 1
mnd 1
bc 5
fnc 5
dl 50
loc 50
rs 10
bpm 1
cpm 1.2
noi 1

5 Functions

Rating   Name   Duplication   Size   Complexity  
A module.exports.getMaxSort 3 3 1
A module.exports.edit 5 5 1
A module.exports.add 4 4 1
A module.exports.first 11 11 1
A module.exports.list 14 14 2

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 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)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
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