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

Create model instance from plain-data object at controller methods #5572

Closed
jonathansolorzn opened this issue May 26, 2020 · 8 comments
Closed
Assignees

Comments

@jonathansolorzn
Copy link

Suggestion

When method hits with a request body we can set it to have a model type, but in the method body the model is just plain-data object.

Use Cases

Since models are classes I'd like to create computed properties for the model like getters, and also have functions to calculate stuff based on the properties that the class has.

Examples

@post('/cards/')
  async create(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Card, {
            title: 'Card'
          }),
        },
      },
    })
    card: Card,
  ): Promise<CardResponse> {
    // Trying to access a computed property of Card form `card` variable is no possible here
    console.log(card.computedGetProperty) //outputs undefined
  }

Acceptance criteria

TBD - will be filled by the team.

@InvictusMB
Copy link
Contributor

This looks more like a bug to me. If I expect a Card instance, I should get a Card instance not a POJO.
Otherwise the definition should say something like card: Raw<Card>

But for now, wouldn't new Card(card).computedGetProperty() do the job for you?

@jonathansolorzn
Copy link
Author

Yeah @InvictusMB I did that

@dhmlau
Copy link
Member

dhmlau commented May 30, 2020

@hacksparrow
Copy link
Contributor

Requirement is not very clear to me.

@InvictusMB
Copy link
Contributor

@hacksparrow
The issue is that an object passed to the controller method does not match the signature of that method. In the example above we have a Card in the signature but get a plain JS object of a similar shape instead of a Card class instance.

This is somewhat related to #2707

@jannyHou
Copy link
Contributor

jannyHou commented Jun 9, 2020

Thank you @InvictusMB seems this story is asking for the same feature as #2707. @fenixsolorzano do you mind if we move all the discussion there? (trying to keep the backlog smaller)

@jannyHou jannyHou self-assigned this Jun 9, 2020
@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Dec 25, 2020
@stale
Copy link

stale bot commented Jul 14, 2021

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants