Skip to content

Commit b68f632

Browse files
authored
Merge pull request #22 from dynamiccast/fix-patch-method-with-prefix
Fix patch method with prefix
2 parents 49f24fb + 7e5b2d9 commit b68f632

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

lib/hook.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ module.exports = function(sails) {
4949

5050
var hook;
5151

52+
const patchRoute = {};
53+
/*
54+
* Patch method does not redirect to the update blueprint by default
55+
* (see https://github.com/balderdashy/sails/pull/2006 for more details)
56+
* We will need to manually redirect all PATCH method to the update blueprint.
57+
*/
58+
patchRoute['PATCH ' + sails.config.blueprints.prefix + '/:model/:id'] = function(req, res) {
59+
let id = req.allParams()['id'];
60+
let model = pluralize.singular(req.param('model'));
61+
62+
req.options.controller = model;
63+
req.options.model = model;
64+
BlueprintController.update(req, res);
65+
};
66+
5267
/**
5368
* Expose blueprint hook definition
5469
*/
@@ -63,21 +78,7 @@ module.exports = function(sails) {
6378
},
6479

6580
routes: {
66-
after: {
67-
/*
68-
* Patch method does not redirect to the update blueprint by default
69-
* (see https://github.com/balderdashy/sails/pull/2006 for more details)
70-
* We will need to manually redirect all PATCH method to the update blueprint.
71-
*/
72-
'PATCH /:model/:id': function(req, res) {
73-
let id = req.allParams()['id'];
74-
let model = pluralize.singular(req.param('model'));
75-
76-
req.options.controller = model;
77-
req.options.model = model;
78-
BlueprintController.update(req, res);
79-
}
80-
}
81+
after: patchRoute
8182
},
8283

8384
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sails-json-api-blueprints",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "Blueprints to turn a Sails.js API into a JSON API",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)