Skip to content

Commit

Permalink
fix: 💩 bind sequelize model to default behaviors. Shame on me for the…
Browse files Browse the repository at this point in the history
… typing
  • Loading branch information
nicgirault committed May 15, 2020
1 parent 45d7f40 commit d3342c9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ export const crud = <M extends any>(
)
router.get(
`${path}/:id`,
getOne((options && options.getOne) || model.findByPk)
getOne((options && options.getOne) || (model.findByPk.bind(model) as any))
)
router.post(
path,
create((options && options.create) || (model.create.bind(model) as any))
)
router.post(path, create((options && options.create) || model.create))
router.put(
`${path}/:id`,
update(
(options && options.update) || model.update,
(options && options.getOne) || model.findByPk
(options && options.update) || (model.update.bind(model) as any),
(options && options.getOne) || (model.findByPk.bind(model) as any)
)
)
router.delete(
`${path}/:id`,
destroy((options && options.create) || model.destroy)
destroy((options && options.create) || (model.destroy.bind(model) as any))
)

return router
Expand Down

0 comments on commit d3342c9

Please sign in to comment.