Commit Graph

56 Commits

Author SHA1 Message Date
Joey Baker
469aaec66f Merge pull request #23 from mdibaiee/fix-joi-concat
Fix (validation) use joi's concat
2016-09-08 13:26:50 -07:00
Joey Baker
c59943a717 Fix (validation) use joi's concat
It turns out defaultsDeep doesn't ever correctly combine Joi objects.
So, the only option is to use Joi's concat method to combine Joi
schemas. This complicates `getConfigForMethod`, but simplifies actual
route creation.

I ran into this because I'm setting up [lout](https://github.com/hapijs/lout)
on a server, and it requires properly formatted Joi schemas. This leads
me to believe there was something already wrong and Lout just exposed
the problem.
2016-09-08 13:20:50 -07:00
Joey Baker
4e078f5ba5 Fix toJSON responses
This is a non-obvious one. Hapi is happy to convert raw sequelize
instances to proper JSON (likely because Sequelize does nice things),
but we do that, we can't use `config.response.schema`, because it
receives the full sequelize instance instead of JSON.

This is a patch release.
2016-09-07 21:06:34 -07:00
Joey Baker
3e9f024dcf Test: now testing get-config-for-method 2016-09-06 11:25:03 -07:00
Joey Baker
4c9ae36c5c Refactor: move get-config-for-method to a file 2016-09-06 11:24:41 -07:00
Joey Baker
f062e2b37f Fix (validation) params is a plain object
If we use a Joi object here, we can't use `defaultsDeep` to extend b/c
the joi prototype won't extend cleanly. We'd need to use joi's `contact`
method, but that gets really complicated and error prone. So, just use
a plain object which is more correct anyway.

http://hapijs.com/tutorials/validation
2016-09-06 07:28:43 -07:00
Joey Baker
69221ea331 Feat query & payload now validated 2016-09-06 07:28:43 -07:00
Joey Baker
f33c8da55d Fix (CRUD update) validate id 2016-09-06 07:28:43 -07:00
Joey Baker
833df49173 Chore add comments for config creation 2016-09-06 07:28:43 -07:00
Joey Baker
32a539c3d9 Fix (crud) update: findOnefindById
b/c `findById` uses an index to lookup, and should be fast.
2016-09-06 07:28:43 -07:00
Joey Baker
b35bd23c91 Fix: prefer user's config before our own 2016-09-06 07:28:43 -07:00
Joey Baker
e0132c2cae Fix: handle all parseInclude errors 2016-09-06 07:28:43 -07:00
Joey Baker
7cecd7fb40 Test (list) add initial list tests 2016-09-05 17:12:13 -07:00
Joey Baker
7b757fcc50 Fix (crud) if no prefix, things still work 2016-09-05 17:11:42 -07:00
Joey Baker
f2f613b35b Fix: boom error on invalid include
Sends a 501 `notImplemented` error when `parseInclude` can't find models
to include.
2016-09-05 17:08:09 -07:00
Joey Baker
bab2e90cbb Feat (error) parse PG 42* errors 2016-09-04 17:28:16 -07:00
Joey Baker
da6b3ce963 Feat (error) include hint on PG errors
Provides useful info!
2016-09-04 17:28:09 -07:00
Joey Baker
b032be20d1 Fix (error) always reply with an error #oops
We had a case where reply would never be called. This could case a
server hang.
2016-09-04 17:28:01 -07:00
Joey Baker
ce6f1fedde Fix: bad merge in error.js 2016-08-28 09:57:23 -07:00
Joey Baker
db86507ef9 Fix: correct babel-polyfill version
This installs the babel-polyfill for babel 6. #oops
2016-08-28 09:56:46 -07:00
Mahdi Dibaiee
17105f66f4 feat(errors): parse sequelize errors and use the relevant Boom error type 2016-08-26 13:15:15 +04:30
Joey Baker
0e9cd935b9 Add: parse Sequelize errors
This adds intelligence around sequelize errors to parse out the correct
error status code and ensure it's always formatted as a Boom error.
2016-08-25 21:28:23 -07:00
Joey Baker
6d289d6d78 Add: Better errors
Now looks at the error that comes back from sequelize and uses boom to
format the error in a more friendly way. This should yield useful error
messages instead of generic 500s.
2016-08-03 14:42:20 -07:00
Joey Baker
79b9fc1242 Change: permissions must always be an array
This allows us to set different configs per model. I should have thought
of this usecase when I first did permissions.
2016-07-22 11:50:08 -07:00
Joey Baker
f95f411a65 Add: permissions
It's now possible to limit the models rest routes are created for. This
is done via a `models` option that can be simple to complex. The readme
has been updated to reflect this.
2016-07-22 10:14:17 -07:00
Mahdi Dibaiee
6c46ff68d0 fix(primaryKey): use model.primaryKey instead of hardcoded id for id routes, fixes #9 2016-07-13 11:27:48 +04:30
Mahdi Dibaiee
29ee49fc62 fix(name): default name parameter on options object itself 2016-07-13 10:05:33 +04:30
Mahdi Dibaiee
d142e6c553 fix(options): take a name parameter, same as the name parameter used in hapi-sequelize, fixes #8 2016-07-13 10:03:00 +04:30
Mahdi Dibaiee
6786b9b487 style: updated eslint config 2016-07-09 09:41:23 +04:30
Mahdi Dibaiee
2d1ab6b75a Merge pull request #6 from Getable/fix-include
Fix: include option api correction
2016-07-09 09:13:14 +04:30
Joey Baker
2ea6c2e3a8 Fix: include option api correction
AFAIK, hapi-sequelize doesn't have a `request.models`, but it does have
a `request.getDb()` method that has `models` on it. This calls that
method to get the related models, but allows `request.models` to keep
working for backward compatibility.
2016-07-08 15:28:33 -07:00
Joey Baker
fee846eb4a Fix: PUT requires a payload to work 2016-07-05 18:34:56 -07:00
Mahdi Dibaiee
07af23cb5a chore(eslint): use eslint for a more consistent style throughout the code 2016-06-30 18:28:02 +04:30
Joey Baker
0698a8a3ad Fix: crud: GET id's can be strings or numbers 2016-06-29 21:30:27 -07:00
Joey Baker
3f419284be Fix: Reply with 404 when required 2016-06-29 21:28:56 -07:00
Ruben Paz
2fd7fa09b0 Replace defaults by defaultsDeep 2016-06-05 17:51:54 +01:00
Ruben Paz
9a28dbcc02 Added defaultConfig parameter to the options 2016-06-05 14:44:24 +01:00
Mahdi Dibaiee
7014e0e07d fix(polyfill): load babel/polyfill if it's not already loaded 2016-05-11 08:55:32 +04:30
Mahdi Dibaiee
dd0084277b fix: actually run destroyAll :| 2016-05-07 10:41:30 +04:30
Mahdi Dibaiee
193aec9619 fix(crud): DELETE plural 2016-05-07 10:37:51 +04:30
Mahdi Dibaiee
973f63640c fix(destroy): associative remove methods require the instance, they don't accept queries, so fallback to manual destroy 2016-04-19 11:39:59 +04:30
Mahdi Dibaiee
544dc23723 fix(associate): associating one way is enough
fix(destroy): directly get a `destroy` method instead of find and destroy
2016-03-31 20:40:01 +04:30
Mahdi Dibaiee
afb08670e8 fix(associate): it seems sometimes associations don't resolve or reject, causing a hang 2016-03-13 14:56:16 +03:30
Mahdi Dibaiee
dc5a010408 fix(crud): typo 2016-03-12 11:05:04 +03:30
Mahdi Dibaiee
5551d416a8 fix(crud): single instance requests were failing, not taking id into account 2016-03-12 10:52:47 +03:30
Mahdi Dibaiee
097a9adcf3 fix(one-to-many): raw parameters are removed 2016-03-12 09:58:05 +03:30
Mahdi Dibaiee
11291f0e08 refactor: minimize repeated code by re-using parseInclude, parseWhere and getMethod
feat(include): ability to specify multiple includes, as an array
2016-03-10 10:48:30 +03:30
Mahdi Dibaiee
00e8e89767 fix(query): use qs for querystring parsing 2016-03-02 12:13:27 +03:30
Mahdi Dibaiee
45d991d1e9 fix: one-to-one associations didn't work properly 2016-02-07 15:52:09 +03:30
Mahdi Dibaiee
5db3bb4eb3 feat(operators): ability to use sequelize operators in queries 2016-02-01 16:46:30 +03:30