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

Pass request body and path parameters as third and second arguments to the controller methods #705

Merged
merged 3 commits into from
May 14, 2020

Conversation

LoicPoullain
Copy link
Member

@LoicPoullain LoicPoullain commented May 14, 2020

Issue

Resolves #507 .

Also fixes bug #706.

Solution and steps

The request body and path parameters are now also passed as third and second arguments to the controller methods.

// Product is here a class validator in this example.

// before
class AppController {

  @Put('/products/:id')
  @ValidateBody(Product)
  updateProduct(ctx: Context) {
    const id = ctx.request.params.id;
    const body = ctx.request.body as Product;

    // Do something.
  }

}

// after
class AppController {

  @Put('/products/:id')
  @ValidateBody(Product)
  updateProduct(ctx: Context, { id }, body: Product) {
    // Do something.
  }

}

Checklist

  • Add/update/check docs (code comments and docs/ folder).
  • Add/update/check tests.
  • Update/check the cli generators.

@LoicPoullain LoicPoullain added this to Work In Progress in Issue tracking May 14, 2020
@codecov
Copy link

codecov bot commented May 14, 2020

Codecov Report

Merging #705 into v1-9-0 will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           v1-9-0     #705   +/-   ##
=======================================
  Coverage   99.65%   99.65%           
=======================================
  Files          94       94           
  Lines        1716     1716           
  Branches      406      405    -1     
=======================================
  Hits         1710     1710           
  Misses          6        6           
Impacted Files Coverage Δ
packages/core/src/sessions/session.ts 100.00% <ø> (ø)
packages/core/src/express/create-middleware.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c70dd64...aa94508. Read the comment docs.

@LoicPoullain LoicPoullain merged commit 2ab5731 into v1-9-0 May 14, 2020
Issue tracking automation moved this from Work In Progress to Done / Closed This Release May 14, 2020
@LoicPoullain LoicPoullain deleted the controller-parameters branch May 14, 2020 14:33
@LoicPoullain LoicPoullain mentioned this pull request May 14, 2020
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Issue tracking
  
Done / Closed This Release
Development

Successfully merging this pull request may close these issues.

None yet

1 participant