Closed remojansen closed 7 years ago
@remojansen it looks like you are getting the default behavior which adds req, res, next to the end of the arguments array that is passed to the RoleFeatureController.delete method. That
what is the value of "authServerPaths.server.roleFeature.endpoints.delete"? what is the value of request.params? The request.params object must contain an "role_id" and "feature_id" property
it is working for me using this code.
@Delete('/:id/:feature_id')
public deleteJob(@RequestParam('id') roleId: string,
@RequestParam('feature_id') featureId: string,
@Request() req: express.Request,
@Response() res: express.Response): Promise<Message> {
return this.jobService.deleteJob(roleId);
}
I have:
@Delete(authServerPaths.server.roleFeature.endpoints.delete)
public async delete(
@RequestParam("role_id") roleId: string,
@RequestParam("feature_id") featureId: string,
@Request() req: express.Request,
@Response() res: express.Response
) {
and authServerPaths.server.roleFeature.endpoints.delete
is /role_feature/:role_id/:feature_id
.
I'm debugging and looks like there is something wrong with here. The else is not invoking Reflect.defineMetadata
? I'm trying a few things...
Fixed! these two lines need to be moved out of the if/else :tada:
@remojansen I'm still having trouble reproducing the problem
On Thu, Apr 6, 2017 at 12:00 PM, Remo H. Jansen notifications@github.com wrote:
Closed #527 https://github.com/inversify/InversifyJS/issues/527 via inversify/inversify-express-utils@bd16e7a https://github.com/inversify/inversify-express-utils/commit/bd16e7a751a7f51e5969163a78d7ccd8870808b9 .
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/inversify/InversifyJS/issues/527#event-1032497651, or mute the thread https://github.com/notifications/unsubscribe-auth/AKvP2Lz_btk9Vrny7v5qLIhuq2JhaGW8ks5rtQwtgaJpZM4M1iM- .
I think you need a controller with multiple methods and multiple annotations in the arguments, to reproduce the issue one method is not enough. Did you try that? I released that change and it is working fine at work for me :)
Ok.. I will try that. I just wanted to reproduce it so I could understand why it was going wrong.
I added a test case. The test case needed to hit this else
.
The original code was:
if (!Reflect.hasOwnMetadata(METADATA_KEY.controllerParameter, target.constructor)) {
parameterMetadataList.unshift(parameterMetadata);
metadataList[methodName] = parameterMetadataList; // !
Reflect.defineMetadata(METADATA_KEY.controllerParameter, metadataList, target.constructor); // !
} else {
metadataList = Reflect.getOwnMetadata(METADATA_KEY.controllerParameter, target.constructor);
if (metadataList.hasOwnProperty(methodName)) {
parameterMetadataList = metadataList[methodName];
}
parameterMetadataList.unshift(parameterMetadata);
}
The if
will generate some metadata thanks to the Reflect.defineMetadata
call but the else
case is not generating any metadata because it is missing the Reflect.defineMetadata
call.
The fixed code is:
if (!Reflect.hasOwnMetadata(METADATA_KEY.controllerParameter, target.constructor)) {
parameterMetadataList.unshift(parameterMetadata);
} else {
metadataList = Reflect.getOwnMetadata(METADATA_KEY.controllerParameter, target.constructor);
if (metadataList.hasOwnProperty(methodName)) {
parameterMetadataList = metadataList[methodName];
}
parameterMetadataList.unshift(parameterMetadata);
}
metadataList[methodName] = parameterMetadataList; // !
Reflect.defineMetadata(METADATA_KEY.controllerParameter, metadataList, target.constructor); // !
@remojansen Looks great! I was able to reproduce the problem. Sorry for all the trouble.
No, problem thanks for your awesome PR :+1:
So I'm testing the 3.5.0 release of
inversify-express-utils
and I have the followingController
:The
@Get()
methodgetById
works as expected and it is binding@RequestParam("id")
,@Request()
and@Response()
correctly. However, the@Delete()
methoi is not binded correctly:@RequestParam("role_id")
is binded to the request.@RequestParam("feature_id")
is binded to the response.@Request()
is binded to thenext
.@Response()
is not binded at all (undefined).It looks like it is just not doing any kind of binding. The same problem takes place on the
@Post
() method.Any ideas of what can be wrong @AltekkeE? Thanks!