rcos/observatory-server

Improve Code Quality in achievement.controller.js

Closed this issue · 1 comments

Clean up tasks:

  • Replace all var statements with either let or const.

  • Replace per-file definitions of handleError with the one defined in api/lib/helpers.js:

import { handleError } from '../lib/helpers'
  • Make whitespace consistent in file (i.e. if(err){ ... should be if (err) { ... )

  • Replace " (double quote) with ' (single quotes) for string constants

  • 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) => {
      ...
    })
  • Replace Mongoose callbacks with promises:

this:

  ClassYear.find({}, function (err, model) {
    if (err) return handleError(err)
    ...
  })

becomes:

  ClassYear.find({})
  .then((model) => {
    ...
  })
  .catch((err) => {
    handleError(err)
  })

Resolved