rcos / observatory-server

A project tracking dashboard for Rensselaer Center for Open Source
https://rcos.io
MIT License
14 stars 51 forks source link

Update ClassYear.getCurrent() function and associated calls throughout app #796

Open aeksco opened 5 years ago

aeksco commented 5 years ago

The ClassYear.getCurrent() uses a callback - it should return a "then-able" object so it can be used with async/await and Promises. See below:

// in classyear.model.js
ClassSchema.statics.getCurrent = function(cb){
  return ClassYear.findOne({ current: true })
};

Update all the locations this function is called in the application - do a find-all for ClassYear.getCurrent.

Also update the ClassYear.getCurrentCodes function to return a "then-able" as well.

aeksco commented 5 years ago

This can be implemented in the controllers like so:

const classYear = await ClassYear.getCurrent().catch((err) => handleError(err))

Love that async/await with the catch statement :+1: