Open aeksco opened 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:
ClassYear.getCurrent()
async/await
// 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.
ClassYear.getCurrent
Also update the ClassYear.getCurrentCodes function to return a "then-able" as well.
ClassYear.getCurrentCodes
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:
catch
The
ClassYear.getCurrent()
uses a callback - it should return a "then-able" object so it can be used withasync/await
and Promises. See below: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.