{"size": 619, "ext": "js", "max_stars_repo_path": "lib/handlers/getLoans.js", "max_stars_repo_name": "akinwale-habibullah/ale-1", "max_stars_repo_stars_event_min_datetime": "2020-08-07T20:09:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-07T20:09:35.000Z", "max_issues_repo_path": "lib/handlers/getLoans.js", "max_issues_repo_name": "akinwale-habibullah/ale-1", "max_issues_repo_issues_event_min_datetime": "2019-09-20T06:38:28.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-20T06:38:28.000Z", "max_forks_repo_path": "lib/handlers/getLoans.js", "max_forks_repo_name": "akinwale-habibullah/ale-1", "max_forks_repo_forks_event_min_datetime": "2019-08-04T14:03:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-21T04:11:26.000Z"}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": 3, "avg_line_length": 19.9677419355, "max_line_length": 59, "alphanum_fraction": 0.5525040388}
/**
 * Get all existing loan requests
 *
 * GET: /loans
 * 
 */

const Loan = require('../../models/loan');
const User = require('../../models/user');
exports.handler = async function getLoans(req, res, next) {
  const { isAdmin } = req;
  try {
    if (!isAdmin) {
      return res.json({
        success: false,
        message: 'Only admins can access this function',
      })
    }
    const loans = await Loan.findAll({
      include: [{ all: true }]
    });
    return res.json({
      success: true,
      message: `All loans returned`,
      data: loans
    })
  } catch (error) {
    return next(error);
  }
}
