var express = require('express');

var MarvelApi = require('../lib/marvelApi');
var router = express.Router();

var marvelApi = new MarvelApi();

/* GET users listing. */
router.get('/characters', function(req, res, next) {
  marvelApi.fetchCharacters(req.query.text).then((resp) => {
    return res.json(resp.data);
  }).catch((err) => {
    return res.json(err);
  })
});

/* GET users listing. */
router.get('/comics/:comicId', function(req, res, next) {
  var comicId = req.params.comicId;

  if (!comicId) {
    return res.json({
      err: 'no comicId given'
    })
  }

  marvelApi.fetchComicInfo(comicId).then((resp) => {
    return res.json(resp.data);
  }).catch((err) => {
    return res.json(err);
  })
});


module.exports = router;
{'avg_line_length': 21.285714285714285, 'max_line_length': 60, 'alphanum_fraction': 0.6228187919463087, 'licenses': ['Apache-2.0'], 'repository_name': 'ronsuez/marvel-api-wrapper', 'path': 'routes/marvel.js', 'size': 745, 'lang': 'JavaScript'}