Issues (791)

src/server/routes/post-sql-request.js (1 issue)

1
import path from 'path'
2
import url from 'url'
3
import {
4
  cmsData
5
  ,abeExtend
6
} from '../../cli'
7
8
var route = function(req, res, next){
9
  abeExtend.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 sourceString = req.body.sourceString
13
  var prefillQuantity = req.body.prefillQuantity
14
  var folder = url.parse(req.header('referer')).path
15
  folder = folder.replace('/abe/editor', '')
16
  folder = path.dirname(folder)
17
  var key = req.body.key
18
  var jsonPage = (req.body.json) ? JSON.parse(JSON.stringify(req.body.json)) : {}
19
20
  jsonPage[key] = null
21
22
  var request = `{{abe type="data" key="${key}" source="${sourceString}" prefill="true" prefill-quantity='${prefillQuantity}' editable="true"}}`
23
  var obj = cmsData.attributes.getAll(request, jsonPage)
24
  
25
  cmsData.source.requestList(obj, folder, request, jsonPage)
26
    .then(() => {
27
28
      res.set('Content-Type', 'application/json')
29
      res.send(JSON.stringify(jsonPage[key]))
30
    })
31
}
32
33
export default route