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

Refactor @param decorator to receive multiple parameters #17

Open
2 tasks
rsaz opened this issue Apr 13, 2024 · 0 comments
Open
2 tasks

Refactor @param decorator to receive multiple parameters #17

rsaz opened this issue Apr 13, 2024 · 0 comments

Comments

@rsaz
Copy link
Member

rsaz commented Apr 13, 2024

Description

Currently expressjs supports requests with multiple parameters as shown:
In the endpoint below we are passing an id and id2 as parameters
http://localhost:3000/users/1/2

In the express.Request you can see the object that lists all these parameters as such:
{ id: '1', id2: '2' }

@Get("/:id/:id2")
    findOne(req: express.Request) {
        console.log(req.params);
        return this.userUseCase.findOne(+req.params.id);
    }

We need to modify the @param decorator to support multiple parameters. Also, we need to investigate the possibility to validate the types passed in the parameter.

The initial idea would be to use the types inferred by the parameter name to either automatically convert to the type suggested.

@Patch("/:id")
    update(@param("id") id: number, @body() userUpdated: IUsersRequestDto) {
        return this.userUseCase.update(id, userUpdated);
    }

As the code above shows, the id would take the property id name and convert by its type, in this case number

Requirement

  • @param decorator with either string or Array. Multiple parameters
  • Type conversation based on the property type
@rsaz rsaz converted this from a draft issue Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant