1
To with a very big doubt, I have a function that makes calculations of users' metrics and I want to put it in an express function to be able to return a JSON and use it in a route, It follows the code to use in the routes:
const calculate_followers_week = (req, res) => {
  let user_id = req.params.id;
  UserHistorySchema.find(user_id ? {
      _id: mongoose.Types.ObjectId(user_id)
    } : {}, {
      'history.created_at': 1,
      'history.meta.indicators': 1
    })
    .lean()
    .exec()
    .then(data => {
      res.status(200).json(data);
    })
    .catch(err => {
      res.status(400).json(err);
    })
}
I want to put a calculation function inside it to have a JSON return.