From 0053167691daa24ab2f32057199325c9dea05689 Mon Sep 17 00:00:00 2001 From: adrianmaurer Date: Tue, 27 May 2014 14:51:19 -0400 Subject: [PATCH 1/3] add slug as a condition check --- lib/server/route/restify.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/server/route/restify.js b/lib/server/route/restify.js index 160217b..284089f 100644 --- a/lib/server/route/restify.js +++ b/lib/server/route/restify.js @@ -326,14 +326,17 @@ Restify.prototype._buildController = function (verb, Model, fields) { function _buildFindQuery(req, id) { var condition = { $or: [] }; - if (id.match(/^[0-9a-fA-F]{24}$/)) { + if (id.match(/^[0-9]{4}[0-9a-fA-F]{20}$/)) { condition.$or.push({ _id: id }); + } else if (id.match(/^[a-z][-a-z0-9]*$/)) { // slug (objectId always starts a 4-byte value representing the seconds since the Unix epoch) + condition.$or.push({ slug: id }); } else { condition.$or.push({ uid: id }); } if (req.body.uid) { condition.$or.push({ uid: req.body.uid }); } + return Model.findOne(condition); } @@ -443,7 +446,7 @@ Restify.prototype.admin = function (path, controller, verbs) { }); }; -Restify.prototype.model = function (path, modelName, overrideController) { +Restify.prototype.model = function (path, modelName, overrideController, auth) { var self = this, Model = mongoose.model(modelName), spec = self._parseSpec(Model); From 7614cb718f603723dce1a67de219a0e1bce97343 Mon Sep 17 00:00:00 2001 From: adrianmaurer Date: Tue, 27 May 2014 14:53:34 -0400 Subject: [PATCH 2/3] clean source --- lib/server/route/restify.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/server/route/restify.js b/lib/server/route/restify.js index 284089f..0d1145a 100644 --- a/lib/server/route/restify.js +++ b/lib/server/route/restify.js @@ -336,7 +336,6 @@ Restify.prototype._buildController = function (verb, Model, fields) { if (req.body.uid) { condition.$or.push({ uid: req.body.uid }); } - return Model.findOne(condition); } @@ -446,7 +445,7 @@ Restify.prototype.admin = function (path, controller, verbs) { }); }; -Restify.prototype.model = function (path, modelName, overrideController, auth) { +Restify.prototype.model = function (path, modelName, overrideController) { var self = this, Model = mongoose.model(modelName), spec = self._parseSpec(Model); From a7f95aad647cc8f0cc02c88646ac97f8b75c498c Mon Sep 17 00:00:00 2001 From: adrianmaurer Date: Tue, 27 May 2014 14:55:44 -0400 Subject: [PATCH 3/3] add contributor credit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 98292c5..c4c2987 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ * [Pilwon Huh](https://github.com/pilwon) (creator, maintainer) * [Brian Park](https://github.com/yaru22) (collaborator) + * [Adrian Maurer](https://github.com/VerticodeLabs) (contributor) Thanks to [all the other contributors](https://github.com/pilwon/node-ultimate/graphs/contributors) as well! :)