Completed
Push — master ( 9899df...273a12 )
by
unknown
02:23
created

src/server/routes/post-reject.js   A

Complexity

Total Complexity 15
Complexity/F 2.14

Size

Lines of Code 61
Function Count 7

Duplication

Duplicated Lines 61
Ratio 100 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A post-reject.js ➔ route 52 52 3

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
import {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
  cmsOperations,
3
  fileUtils,
4
  Hooks,
5
  Manager
6
} from '../../cli'
7
8
var route = function(req, res, next){
9
  Hooks.instance.trigger('beforeRoute', req, res, next)
10
  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...
11
12
  var p = new Promise((resolve) => {
13
    cmsOperations.save.save(
14
      fileUtils.getFilePath(req.body.filePath),
15
      req.body.tplPath,
16
      req.body.json,
17
      '',
18
      'draft',
19
      null,
20
      'reject')
21
      .then(() => {
22
        resolve()
23
      }).catch(function(e) {
24
        console.error(e)
25
      })
26
  })
27
28
  p.then((resSave) => {
29
    cmsOperations.save.save(
30
      fileUtils.getFilePath(req.body.filePath),
31
      req.body.tplPath,
32
      req.body.json,
33
      '',
34
      'reject',
35
      resSave,
36
      'reject')
37
      .then((resSave) => {
38
        if(typeof resSave.error !== 'undefined' && resSave.error !== null  ){
39
          res.set('Content-Type', 'application/json')
40
          res.send(JSON.stringify({error: resSave.error}))
41
        }
42
        var result
43
        if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){
44
          result = resSave
45
        }
46
        if(typeof resSave.json !== 'undefined' && resSave.json !== null){
47
          result = {
48
            success: 1,
49
            json: resSave.json
50
          }
51
        }
52
        Manager.instance.updateList()
53
        res.set('Content-Type', 'application/json')
54
        res.send(JSON.stringify(result))
0 ignored issues
show
Bug introduced by
The variable result does not seem to be initialized in case typeof resSave.reject !...resSave.reject !== null on line 43 is false. Are you sure the function stringify handles undefined variables?
Loading history...
55
      })
56
  }).catch(function(e) {
57
    console.error(e)
58
  })
59
}
60
61
export default route