<commit_before>import express from 'express'
import {Album, Artist, Track} from './models'

const guard = (req, res, next) => {
  try {
    next()
  } catch (error) {
    console.error(error) // eslint-disable-line
    res.sendStatus(500)
  }
}

const all = Model => async (req, res) =>
  res.send(await Model.fetchAll())

const one = Model => async (req, res) => {
  const model = await Model.forge({id: req.params.id})
  if (model) res.send(model)
  else res.sendStatus(404)
}

const albumsByArtist = async (req, res) =>
  res.send(await Artist.forge({id: req.params.id}).albums())

const api = express.Router() // eslint-disable-line

api.use(guard)

api.get('/artists', all(Artist))
api.get('/albums', all(Album))
api.get('/tracks', all(Track))<commit_msg>Fix server guard middleware<commit_after>import express from 'express'
import {Album, Artist, Track} from './models'

const guard = async (req, res, next) => {
  try {
    await next()
  } catch (error) {
    console.error(error) // eslint-disable-line
    res.sendStatus(500)
  }
}

const all = Model => async (req, res) =>
  res.send(await Model.fetchAll())

const one = Model => async (req, res) => {
  const model = await Model.forge({id: req.params.id})
  if (model) res.send(model)
  else res.sendStatus(404)
}

const albumsByArtist = async (req, res) =>
  res.send(await Artist.forge({id: req.params.id}).albums())

const api = express.Router() // eslint-disable-line

api.use(guard)

api.get('/artists', all(Artist))
api.get('/albums', all(Album))
api.get('/tracks', all(Track))
{'fraction_non_alphanumeric': 0.17981888745148772, 'fraction_numerical': 0.007761966364812419, 'mean_word_length': 3.9583333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4287599', 'n_tokens_mistral': 559, 'n_tokens_neox': 545, 'n_words': 134}