endpoints/endpoints

View on GitHub
src/store-bookshelf/lib/by_id.js

Summary

Maintainability
A
55 mins
Test Coverage
import Kapow from 'kapow';

export default function byId (model, id, relations) {
  return model.collection().query(function (qb) {
     return qb.where({id:id});
   }).fetchOne({
     withRelated: relations
   }).catch(TypeError, function(e) {
     // A TypeError here most likely signifies bad
     // relations passed into withRelated
     throw Kapow(404, 'Unable to find relations');
   });
}