Skip to content

Commit

Permalink
fix: Correct handling of blueprint actions overridden in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsharvey authored and theoomoregbee committed Jun 4, 2020
1 parent 366bf3f commit a466521
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 64 deletions.
6 changes: 6 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ module.exports.routes = {
'POST /user': {
controller: 'UserController',
action: 'create',
dummy: true,
},

'patch /user': {
model: 'user',
action: 'user/create',
},

'post /user/login': {
Expand Down
28 changes: 28 additions & 0 deletions lib/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ export const parseBoundRoutes = (boundRoutes: Array<Sails.Route>,
originalFn: { /*[Function] */ _middlewareType: 'BLUEPRINT: find' }
};

/* example of standard blueprint route but with standard action overridden in controller */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const standardBlueprintRouteWithOverriddenActionExampleForReference = {
path: '/user',
target: '[Function: routeTargetFnWrapper]',
verb: 'post',
options: {
model: 'user',
associations: [ /* [Object], [Object], [Object] */ ],
autoWatch: true,
detectedVerb: { verb: '', original: '/user', path: '/user' },
action: 'user/create',
_middlewareType: 'ACTION: user/create',
skipRegex: []
},
originalFn: /* [Function] */ { _middlewareType: 'ACTION: user/create' }
};

/* example of Sails.Route for custom route targetting blueprint action */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const customRouteTargettingBlueprintExampleForReference = {
Expand Down Expand Up @@ -260,6 +278,16 @@ export const parseBoundRoutes = (boundRoutes: Array<Sails.Route>,
const parsedPath = parsePath(route.path);
// let middlewareType, action, actionType;

if (_middlewareType === 'action' && routeOptions.action) {
const [modelIdentity, actionToCheck] = routeOptions.action.split('/');
if(modelIdentity === routeOptions.model) {
/* blueprint actions `{model}/{blueprintAction}` may be overriden by custom
* controller actions and thus annotated differently */
_middlewareType = 'blueprint';
mwtAction = actionToCheck;
}
}

if (_middlewareType === 'action') {

return {
Expand Down
Loading

0 comments on commit a466521

Please sign in to comment.