0

I am trying to make a put request on the url http://[::1]:3000/carts?filter[where][user_id]=5&filter[where][cart_id]=52 with two parameters respectively 'user_id' and 'user_id'. This is what I have tried .

@put('/carts?filter[where][user_id]={u_id}&filter[where][cart_id]={id}', {
    responses: {
      '204': {
        description: 'Cart PUT success',
      },
    },
  })
  async replaceById2(
    @param.path.number('u_id') u_id: number,
    @param.path.number('id') id: number,


    @requestBody() cart: Cart,
  ): Promise<void> {
    await this.cartRepository.replaceById(id, cart);
  }

I am passing two parameters from frontend to update data respectively 'user_id' and 'cart_id'.

  updatecartItem (user_id,id,cart): Observable<any> {
    return this.http.put(this.cart_url + 'carts?filter[where][user_id]=' + user_id +'&filter[where][cart_id]=' + id, cart, {observe : 'response'})

  }

But I am getting 404 error as follows

statusCode: 404 name: "NotFoundError" message: "Endpoint "PUT /carts" not found."

Can you please direct me in creating custom put request with more than one parameters

pratik jaiswal
  • 1,855
  • 9
  • 27
  • 59
  • shouldn't you use `param.query.number` instead `path`? – Salitha Dec 16 '19 at 08:31
  • Still not working. – pratik jaiswal Dec 16 '19 at 08:51
  • what i do usually for any request (`GET`,`POST` or `PUT`) is define the endpoint as `@put('/cart')` and then decorate inputs like you did. Now send request like `/cart?u_id=10&id=15`. – Salitha Dec 16 '19 at 09:23
  • Can you please show me how to do this. Some code? – pratik jaiswal Dec 16 '19 at 10:12
  • Try replacing `@put('/carts?filter[where][user_id]={u_id}&filter[where][cart_id]={id}',...` with `@put('/carts',...` and your client request with `return this.http.put(this.cart_url + 'carts?user_id=' + user_id +'&id=' + id, cart,...` **And** also make sure `this.cart_url` has the correct url base. I suggest you to test api with `postman`. – Salitha Dec 16 '19 at 10:25
  • The scenario is cart belongs-to the user. This cart contains list of all products, users have added to their carts. Now I can easily update cart by only its 'cart_id', but in the background, it traverses all records, but I want it to traverse only the records where user_id is for example "2" – pratik jaiswal Dec 16 '19 at 10:48
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/204333/discussion-between-salitha-indrajith-pathiraja-and-pratik-jaiswal). – Salitha Dec 16 '19 at 10:53

0 Answers0