const stat = require("../services/stats.services");

async function get(req, res, next) {
  // API V1
  try {
    res.json(await stat.hits());
  } catch (err) {
    console.error("Controller Error", err);
    err.status = 500;
    next(err);
  }
}

async function versions(req, res, next) {
  // API v2
  try {
    res.json(await stat.getVersions());
  } catch (err) {
    console.error("Controller Error", err);
    err.status = 500;
    next(err);
  }
}

async function statistics(req, res, next) {
  // Api v2
  try {
    res.json(await stat.statistics());
  } catch (err) {
    console.error("Controller Error", err);
    err.status = 500;
    next(err);
  }
}

module.exports = {
  get,
  versions,
  statistics,
};
