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

feature(core): allow Array in request mapping decorator #1385

Conversation

elyesbenabdelkader
Copy link
Contributor

@elyesbenabdelkader elyesbenabdelkader commented Dec 19, 2018

This feature was requested in the issue #1343. When routing, besides using a single string, you can
now use an array of strings in the Post, Get, ... decorators.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #1343

What is the new behavior?

When routing, besides using a single string, you can now use an array of strings in the Post, Get, ... decorators.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1330

  • 20 of 21 (95.24%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.009%) to 93.764%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/core/router/router-explorer.ts 18 19 94.74%
Totals Coverage Status
Change from base Build 1323: -0.009%
Covered Lines: 2868
Relevant Lines: 2992

💛 - Coveralls

@coveralls
Copy link

coveralls commented Dec 19, 2018

Pull Request Test Coverage Report for Build 1371

  • 11 of 11 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 93.791%

Totals Coverage Status
Change from base Build 1339: 0.02%
Covered Lines: 2856
Relevant Lines: 2979

💛 - Coveralls

);
const paths = [];
scannedPaths.forEach(p => {
while (p.pathAlternatives.length) {
Copy link
Member

Choose a reason for hiding this comment

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

Cannot we add simple flattening logic (flatMap)? For example, using .reduce() method with a pure function passed as a callback which returns flatten array?

@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Dec 25, 2018

Thanks @elyesbenabdelkader for your PR. I left a few comments 🙂

pathAlternatives = pathAlternatives.slice(1);
} else {
path = this.validateRoutePath(routePath);
}
Copy link
Member

Choose a reason for hiding this comment

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

We should treat path as an array by default - in the worst case, it would contain a single element. Hence, we wouldn't have to hold two variables (and consequently, pass them as parameters to another method).

@@ -23,6 +23,7 @@ import { RouterProxy, RouterProxyCallback } from './router-proxy';

export interface RoutePathProperties {
path: string;
pathAlternatives: string[];
Copy link
Member

Choose a reason for hiding this comment

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

Is it required? See below.

@elyesbenabdelkader
Copy link
Contributor Author

Treating path as an array would introduce a lot of changes all over the packages. That's why I tried to preserve the same RoutePathProperties structure and simply use pathAlternatives as a mean to do so. Hence when you call scanForPaths you get an array of RoutePathProperties where path is a string (the default expected behavior).

@kamilmysliwiec
Copy link
Member

I fully understand. However, I believe that it would be worth from the code quality perspective to merge these parameters anyway (even if it requires more code changes).

This feature was requested in the issue nestjs#1343. When routing, besides using a single string, you can
now use an array of strings in the Post, Get, ... decorators.
@kamilmysliwiec kamilmysliwiec merged commit ea700d8 into nestjs:master Feb 5, 2019
@kamilmysliwiec
Copy link
Member

LGTM. Thanks!

@elyesbenabdelkader elyesbenabdelkader deleted the feature/request-mapping-decorator branch February 5, 2019 20:47
@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants