Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request for issue #521 https://github.com/inversify/InversifyJS/… #41

Merged
merged 4 commits into from
Apr 2, 2017

Conversation

dcavanagh
Copy link
Member

@dcavanagh dcavanagh commented Mar 31, 2017

Add Decorators for binding method parameters to request parameters like in Spring or node-decorators

Description

@request - binds a method parameter to the request object - still provided at the end of the arguments list for backwards compatibility
@response - binds a method parameter to the response object - still provided at the end of the arguments list for backwards compatibility
@RequestParam - binds a method parameter to request.params or to a specific parameter if a name is passed
@QueryParam - binds a method parameter to request.query or to a specific query parameter if a name is passed
@RequestBody - binds a method parameter to request.body or to a specific body property if a name is passed
@RequestHeaders - binds a method parameter to the request headers
@Cookies - binds a method parameter to the request cookies
@Next - binds a method parameter to the next() function - still provided at the end of the arguments list for backwards compatibility

Related Issue

issue 521
inversify/InversifyJS#521

Motivation and Context

Better developer experience than using request and response
modeled after spring and node-decorators
some code reused from node-decorators

How Has This Been Tested?

unit tests for new code
original unit tests still pass
backwards compatible
node v7.4.0

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

@Dirrk Dirrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to point out some minor things I noticed that probably weren't meant to be in the PR that can save someone some time before they actually review this.

README.md Outdated

### `@RequestBody(name?: string)`
binds a method parameter to request.body or to a specific body property if a name is passed-']'ok89im.jo;iuh:'

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to commit this?

']'ok89im.jo;iuh:'

"**/dist": true,
"**/docs": true,
"type_definitions/**/*.js": true
"**/.DS_Store": true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like auto formatting was it intended to be committed?


export function Controller(path: string, ...middleware: interfaces.Middleware[]) {
return function (target: any) {
let metadata: interfaces.ControllerMetadata = {path, middleware, target};
let metadata: interfaces.ControllerMetadata = { path, middleware, target };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I think this is your ide making an unexpected change?

@@ -39,7 +39,7 @@ export function Delete(path: string, ...middleware: interfaces.Middleware[]): in

export function Method(method: string, path: string, ...middleware: interfaces.Middleware[]): interfaces.HandlerDecorator {
return function (target: any, key: string, value: any) {
let metadata: interfaces.ControllerMethodMetadata = {path, middleware, method, target, key};
let metadata: interfaces.ControllerMethodMetadata = { path, middleware, method, target, key };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

src/constants.ts Outdated
};

export enum ParameterType {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be capitalized like the other constants?

@lholznagel
Copy link
Contributor

Thanks!
Will also take a look later

@dcavanagh
Copy link
Member Author

dcavanagh commented Apr 1, 2017 via email

@lholznagel
Copy link
Contributor

@AltekkeE just push more commits to the current branch. It will auto update this pr :)

Changed ParameterType to PARAMETER_TYPE
Formatting in README.md
@dcavanagh
Copy link
Member Author

dcavanagh commented Apr 1, 2017

@lholznagel - Done.

I also notice that the code coverage report is not working correctly. It says 100% but no files are actually checked. This may be happening in the main inversify repo too.
-edit: removed copy of previous comment from email

@@ -42,12 +42,17 @@ export class FooController implements interfaces.Controller {
constructor( @inject('FooService') private fooService: FooService ) {}

@Get('/')
private index(req: express.Request): string {
private index(req: express.Request, res: express.Response, next: express.NextFunction): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn´t we just use @QueryParam('id') id: string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to show that you can still do it the original way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to show that you can still do it the original way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay.
Makes sense

@lholznagel
Copy link
Contributor

LGTM 👍

@remojansen
Copy link
Member

👍 Amazing PR 💯 thanks a lot for this contribution. One question: did you find a way to fix the test coverage reports?

@remojansen remojansen merged commit b994a59 into inversify:master Apr 2, 2017
@lholznagel
Copy link
Contributor

@remojansen yesterday I checked travis and the problem is also in the main repo since some time.
I did a quick look to find a solution, but until now I didn´t find anything.

@remojansen
Copy link
Member

I think is probably some breaking change in one of the tools but is hard to find out which one :(

@dcavanagh
Copy link
Member Author

dcavanagh commented Apr 2, 2017 via email

@remojansen
Copy link
Member

Thanks a lot I will create an issue to track this down and see if we can fix it 👍

@remojansen
Copy link
Member

Just release [email protected] which includes this feature 🎉

@remojansen
Copy link
Member

Hi @AltekkeE I have noticed that in the docs you mention @RequestParams but it seems to be not available in the source code. Did you forget to commit it? Thanks!

@dcavanagh
Copy link
Member Author

@remojansen I will take a look right now

@dcavanagh
Copy link
Member Author

😬 Spelling mistake, Should be @RequestParam in the docs. It is correct down in the description part just not in that delete statement

@remojansen
Copy link
Member

No worries.Would u like to send a PR?

@dcavanagh
Copy link
Member Author

dcavanagh commented Apr 3, 2017

@remojansen [Gulp Problem] The problem is with gulp-mocha v4. I downgraded to ^3.0 and it works again.

In a project that I am working on we are not using gulp. We just run the nyc using npm

"scripts": {
    "start": "node ./dist/bootstrap.js",
    "postinstall": "tsc",
    "test": "mocha --opts mocha.opts && rm -rf test",
    "test:dev": "mocha --opts mocha.opts --watch",
    "cover": "nyc npm run test"
  }

the issue below points to this as well.

SBoudrias/gulp-istanbul#115

@dcavanagh dcavanagh mentioned this pull request Apr 3, 2017
9 tasks
remojansen pushed a commit that referenced this pull request Apr 3, 2017
* Fixed README.md @RequestParams to @RequestParam

* After fixing the code coverage output I noticed that some lines were not covered
Fixed @Cookies framework test to cover code in server.ts
Removed unused code from decorators.ts
@dcavanagh dcavanagh mentioned this pull request Apr 4, 2017
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants