Comparing version 0.4.1 to 0.4.2
@@ -40,2 +40,3 @@ // Dependencies | ||
controller.set('plural', options.plural || lingo.en.pluralize(options.singular)); | ||
controller.set('findBy', options.findBy || '_id'); | ||
@@ -42,0 +43,0 @@ controller.set('basePath', basePath); |
@@ -0,1 +1,11 @@ | ||
// Private Members | ||
// --------------- | ||
function getFindCondition (request) { | ||
var conditions = {}; | ||
conditions[request.app.get('findBy')] = request.params.id; | ||
return conditions; | ||
} | ||
// Module Definition | ||
// ----------------- | ||
var middleware = module.exports = { | ||
@@ -5,3 +15,3 @@ // Retrieve header for the addressed document | ||
var Model = request.app.get('model'); | ||
request.baucis.query = Model.findById(request.params.id); | ||
request.baucis.query = Model.findOne(getFindCondition(request)); | ||
next(); | ||
@@ -18,3 +28,3 @@ }, | ||
var Model = request.app.get('model'); | ||
request.baucis.query = Model.findById(request.params.id); | ||
request.baucis.query = Model.findOne(getFindCondition(request)); | ||
next(); | ||
@@ -101,3 +111,7 @@ }, | ||
request.baucis.query = Model.findByIdAndUpdate(id, request.body, { upsert: true }); | ||
request.baucis.query = Model.findOneAndUpdate( | ||
getFindCondition(request, id), | ||
request.body, | ||
{ upsert: true } | ||
); | ||
next(); | ||
@@ -112,3 +126,3 @@ }, | ||
var Model = request.app.get('model'); | ||
request.baucis.query = Model.remove({ _id: request.params.id }); | ||
request.baucis.query = Model.remove(getFindCondition(request)); | ||
next(); | ||
@@ -115,0 +129,0 @@ }, |
{ | ||
"name": "baucis", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -1,3 +0,3 @@ | ||
baucis v0.4.1 | ||
=============== | ||
baucis v0.4.2 | ||
============= | ||
@@ -4,0 +4,0 @@ Baucis is Express middleware that creates configurable REST APIs using Mongoose schemata. |
273281
1046