rcos / observatory-server

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

Replace callbacks with async/await in smallgroup.controller.js #792

Open aeksco opened 6 years ago

aeksco commented 6 years ago

All our Express.js controllers use callbacks when interacting with our Mongoose models - like so:

exports.index = (req, res) => {
    SmallGroup.find({}, (err, smallgroups) => {
        if (err) { return handleError(res, err); }
        return res.status(200).json(smallgroups);
    });
};

These functions should be updated to use the async/await syntax, like so:

exports.index = async (req, res) => {
  const smallgroups = await SmallGroup.find({}).catch((err) => { return handleError(res, err); })
  return res.status(200).json(smallgroups);
};

@TungE LMK if you've got any questions - sorry for the delay!

aeksco commented 6 years ago

@TungE Just a note - start doing this in the smallgroup.controller.js file - work on one function at a time, and commit your changes after you update each function. You can run npm test from the observatory-server root to ensure that your changes haven't broken anything :+1: