Skip to content

Commit a466521

Browse files
danielsharveytheoomoregbee
authored andcommitted
fix: Correct handling of blueprint actions overridden in controller
1 parent 366bf3f commit a466521

File tree

3 files changed

+278
-64
lines changed

3 files changed

+278
-64
lines changed

config/routes.js

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ module.exports.routes = {
5858
'POST /user': {
5959
controller: 'UserController',
6060
action: 'create',
61+
dummy: true,
62+
},
63+
64+
'patch /user': {
65+
model: 'user',
66+
action: 'user/create',
6167
},
6268

6369
'post /user/login': {

lib/parsers.ts

+28
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ export const parseBoundRoutes = (boundRoutes: Array<Sails.Route>,
8989
originalFn: { /*[Function] */ _middlewareType: 'BLUEPRINT: find' }
9090
};
9191

92+
/* example of standard blueprint route but with standard action overridden in controller */
93+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
94+
const standardBlueprintRouteWithOverriddenActionExampleForReference = {
95+
path: '/user',
96+
target: '[Function: routeTargetFnWrapper]',
97+
verb: 'post',
98+
options: {
99+
model: 'user',
100+
associations: [ /* [Object], [Object], [Object] */ ],
101+
autoWatch: true,
102+
detectedVerb: { verb: '', original: '/user', path: '/user' },
103+
action: 'user/create',
104+
_middlewareType: 'ACTION: user/create',
105+
skipRegex: []
106+
},
107+
originalFn: /* [Function] */ { _middlewareType: 'ACTION: user/create' }
108+
};
109+
92110
/* example of Sails.Route for custom route targetting blueprint action */
93111
// eslint-disable-next-line @typescript-eslint/no-unused-vars
94112
const customRouteTargettingBlueprintExampleForReference = {
@@ -260,6 +278,16 @@ export const parseBoundRoutes = (boundRoutes: Array<Sails.Route>,
260278
const parsedPath = parsePath(route.path);
261279
// let middlewareType, action, actionType;
262280

281+
if (_middlewareType === 'action' && routeOptions.action) {
282+
const [modelIdentity, actionToCheck] = routeOptions.action.split('/');
283+
if(modelIdentity === routeOptions.model) {
284+
/* blueprint actions `{model}/{blueprintAction}` may be overriden by custom
285+
* controller actions and thus annotated differently */
286+
_middlewareType = 'blueprint';
287+
mwtAction = actionToCheck;
288+
}
289+
}
290+
263291
if (_middlewareType === 'action') {
264292

265293
return {

0 commit comments

Comments
 (0)