Completed
Push — master ( 7ee597...82641a )
by greg
01:56
created

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

Complexity

Total Complexity 7
Complexity/F 7

Size

Lines of Code 34
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
C get-paginate.js ➔ route 0 26 7
1
import {
2
  abeExtend,
3
  cmsOperations,
0 ignored issues
show
Unused Code introduced by
The variable cmsOperations seems to be never used. Consider removing it.
Loading history...
4
  Manager
5
} from '../../cli'
6
7
var route = function(req, res, next){
8
  var currentPage = 1
9
  var pageSize = 2
10
  var sortField = 'date'
11
  var sortOrder = -1
12
13
  abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
14
  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...
15
16
  if (typeof req.query.page !== 'undefined') {
17
    currentPage = +req.query.page;
18
  }
19
  if (typeof req.query.pageSize !== 'undefined') {
20
    pageSize = +req.query.pageSize;
21
  }
22
  if (typeof req.query.sortField !== 'undefined') {
23
    sortField = req.query.sortField;
24
  }
25
  if (typeof req.query.sortOrder !== 'undefined') {
26
    sortOrder = +req.query.sortOrder;
27
  }
28
  var page = Manager.instance.getPage(currentPage, pageSize, sortField, sortOrder)
29
30
  res.set('Content-Type', 'application/json')
31
  res.send(JSON.stringify(page))
32
}
33
34
export default route