mikec / kalamata

Extensible REST API for Express + Bookshelf.js
MIT License
41 stars 12 forks source link

Hooks break when changing endpointName #2

Closed graemetait closed 8 years ago

graemetait commented 8 years ago

If you change the endpointName you receive the following error when trying to use a hook.

node_modules/kalamata/src/index.js:248
            hooks[opts.endpointName][prefix][type].push(fn);
                                    ^
TypeError: Cannot read property 'before' of undefined

Here's a snippet of the code that produces this. The students table is actually named ncl_students, and as Bookshelf doesn't support table name prefixes I have to set the endpointName manually like so:

api.expose(Student, { endpointName: 'students' });
api.beforeGetStudent(function(req, res, student) {};

Unfortunately hooks still seems to use the actual table name, as it looks like this when I console.log it, and this seems to be causing the error.

{ ncl_students:
   { before:
      { get: [],
        getCollection: [],
        getRelated: [],
        create: [],
        update: [],
        del: [] },
     after:
      { get: [],
        getCollection: [],
        getRelated: [],
        create: [],
        update: [],
        del: [] } } }
graemetait commented 8 years ago

Fixed by PR #3.