Skip to content

Refactor @param decorator to receive multiple parameters #17

@rsaz

Description

@rsaz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions