fix(crud): single instance requests were failing, not taking id into account

This commit is contained in:
Mahdi Dibaiee 2016-03-12 10:52:47 +03:30
parent 097a9adcf3
commit 5551d416a8
2 changed files with 3 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "hapi-sequelize-crud", "name": "hapi-sequelize-crud",
"version": "2.0.1", "version": "2.0.2",
"description": "Hapi plugin that automatically generates RESTful API for CRUD", "description": "Hapi plugin that automatically generates RESTful API for CRUD",
"main": "build/index.js", "main": "build/index.js",
"config": { "config": {

View File

@ -45,6 +45,7 @@ export const get = (server, model) => {
async handler(request, reply) { async handler(request, reply) {
const include = parseInclude(request); const include = parseInclude(request);
const where = parseWhere(request); const where = parseWhere(request);
if (request.params.id) where.id = request.params.id;
const instance = await model.findOne({ where, include }); const instance = await model.findOne({ where, include });
@ -109,6 +110,7 @@ export const destroy = (server, model) => {
async handler(request, reply) { async handler(request, reply) {
const include = parseInclude(request); const include = parseInclude(request);
const where = parseWhere(request); const where = parseWhere(request);
if (request.params.id) where.id = id;
const list = await model.findAll({ where }); const list = await model.findAll({ where });