src/server/routes/get-paginate.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 5

Size

Lines of Code 51
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 51
rs 10
wmc 10
mnd 2
bc 7
fnc 2
bpm 3.5
cpm 5
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
D get-paginate.js ➔ route 0 43 9
1
import {
2
  config,
3
  abeExtend,
4
  Manager
5
} from '../../cli'
6
7
var route = function(req, res, next){
8
  var start = 0
9
  var length = 25
10
  var sortField = 'date'
11
  var sortOrder = -1
12
  var search = ''
13
  
14
  var values = ['date', 'abe_meta.link', 'abe_meta.template', 'date']
15
  Array.prototype.forEach.call(config.users.workflow, (flow) => {
16
    values[i] = 'abe_meta.' + flow
17
    ++i
18
  })
19
20
  abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
21
  if(typeof res._header !== 'undefined' && res._header !== null) return
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...
22
23
  if (typeof req.query.start !== 'undefined') {
24
    start = +req.query.start
25
  }
26
27
  if (typeof req.query.length !== 'undefined') {
28
    length = +req.query.length
29
  }
30
31
  var i = 4
32
  if (typeof req.query.order !== 'undefined') {
33
    sortField = values[req.query.order[0]['column']]
34
    sortOrder = (req.query.order[0]['dir'] === 'desc')? -1:1
35
  }
36
37
  if (typeof req.query.search.value !== '') {
38
    search = req.query.search.value
39
  }
40
41
  var list = Manager.instance.getPage(start, length, sortField, sortOrder, search)
42
43
  if (typeof req.query.draw !== 'undefined') {
44
    list['draw'] = req.query.draw
45
  }
46
47
  res.set('Content-Type', 'application/json')
48
  res.send(JSON.stringify(list))
49
}
50
51
export default route
52