Skip to content

How to implement updateById for an array of items #7351

Answered by marioestradarosa
emazzu asked this question in Q&A
Discussion options

You must be logged in to vote

@emazzu , you can traverse the array parameter and I recommend you use updateById method instead of replaceById. In the following example, I receive an array of TaxReturn models and iterate thru each of them. Notice also the OPENAPI spec I placed in the requestBody().

I didn't placed a try{} catch{} block on the updateById in my case, but be aware that it can throw the EntityNotFound error whenever the id of the payload item cannot be found in the database.

 @put('/replace/taxforms/')
  @response(204, {
    description: 'TaxReturn PUT success',
  })
  async updateArrayPayLoad(
    @requestBody(
      {
        content: {
          'application/json': {
            schema: {
              t…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by marioestradarosa
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants