hapi-crud-promise
Advanced tools
Comparing version 0.2.0 to 0.3.0
31
index.js
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = (server, options) => { | ||
const reallAllPost = options.path.slice(0, options.path.lastIndexOf('/')) | ||
const readAllPost = options.path.slice(0, options.path.lastIndexOf('/')) | ||
@@ -24,5 +24,5 @@ let baseOpts = _.omit(_.cloneDeep(options), [ | ||
if(options.crudReadAll) { | ||
server.route(_.merge(baseOpts, { | ||
const readAll = _.merge(_.cloneDeep(baseOpts), { | ||
method: 'GET', | ||
path: reallAllPost, | ||
path: readAllPost, | ||
config: { | ||
@@ -36,9 +36,10 @@ validate: { | ||
} | ||
})); | ||
}); | ||
server.route(readAll); | ||
} | ||
if(options.crudCreate) { | ||
server.route(_.merge(baseOpts, { | ||
const create = _.merge(_.cloneDeep(baseOpts), { | ||
method: 'POST', | ||
path: reallAllPost, | ||
path: readAllPost, | ||
config: { | ||
@@ -52,7 +53,8 @@ validate: { | ||
} | ||
})); | ||
}); | ||
server.route(create); | ||
} | ||
if(options.crudRead) { | ||
server.route(_.merge(baseOpts, { | ||
const read = _.merge(_.cloneDeep(baseOpts), { | ||
method: 'GET', | ||
@@ -68,7 +70,8 @@ path: options.path, | ||
} | ||
})); | ||
}); | ||
server.route(read); | ||
} | ||
if(options.crudUpdate) { | ||
server.route(_.merge(baseOpts, { | ||
const update = _.merge(_.cloneDeep(baseOpts), { | ||
method: 'PUT', | ||
@@ -85,7 +88,8 @@ path: options.path, | ||
} | ||
})); | ||
}); | ||
server.route(update); | ||
} | ||
if(options.crudDelete) { | ||
server.route(_.merge(baseOpts, { | ||
const del = _.merge(_.cloneDeep(baseOpts), { | ||
method: 'DELETE', | ||
@@ -101,4 +105,5 @@ path: options.path, | ||
} | ||
})); | ||
}); | ||
server.route(del); | ||
} | ||
} |
{ | ||
"name": "hapi-crud-promise", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Easily create CRUD routes on a hapi server by providing a path and promises for each of the actions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,3 +29,3 @@ 'use strict'; | ||
query: { | ||
thingId: Joi.string().required() | ||
limit: Joi.string().optional() | ||
}, | ||
@@ -141,3 +141,3 @@ params: { | ||
it.only('should pass along other options to server', () => { | ||
it('should pass along other options to server', () => { | ||
server.register(require('hapi-auth-basic')) | ||
@@ -144,0 +144,0 @@ server.auth.strategy('simple', 'basic', { validateFunc: (() => {true}) }); |
14782
374