rcos/observatory-server

Improve code quality in API helpers.js

Closed this issue · 1 comments

Update the handleError function to return { error: err } and set status manually, like so:

// Return a standard error
export const handleError = (res, err) => {
  return res.status(500).json({ error: err }).end()
}

Repeat this process for the validationError function.

Additionally:

  • replace all var statements with either let or const.
  • Make whitespace consistent in file (i.e. if(err){ ... should be if (err) { ... )
  • Replace " (double quote) with ' (single quotes)
  • Replace function keyword with => function syntax, i.e.:
    this:
  ClassYear.findOne({"dayCodes.code":code})
    .exec(function(err, classYear){
      ...
    })

becomes:

  ClassYear.findOne({"dayCodes.code":code})
    .exec((err, classYear) => {
      ...
    })

Resolved