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

upsertWithWhere Verb ( POST or PUT ) #324

Closed
1 of 4 tasks
davidpestana opened this issue Jan 19, 2017 · 2 comments · Fixed by #336
Closed
1 of 4 tasks

upsertWithWhere Verb ( POST or PUT ) #324

davidpestana opened this issue Jan 19, 2017 · 2 comments · Fixed by #336

Comments

@davidpestana
Copy link

davidpestana commented Jan 19, 2017

What type of issue are you creating?

  • [*] Bug
  • Enhancement
  • Question

What version of this module are you using?

  • 2.0.10 (Stable)
  • [*] 2.1.0-rc.n (2.1 Release Candidate n)
  • Other

Write other if any:

Please add a description for your issue:

i am using now upsertWithWhere and this method was a fail because dont are using the post verb... are using the put verb and dont works fine, maybe will be a bug?

fixing SDK generated with replacing PUT for POST ... works fine

Thanks!!

/**

public upsertWithWhere(where: any = {}, data: any = {}): Observable {
let _urlParams: any = {};
if (where) _urlParams.where = where;
return this.request('PUT', [
LoopBackConfig.getPath(),
LoopBackConfig.getApiVersion(),
this.model.getModelDefinition().plural,
'upsertWithWhere'
].join('/'), undefined, _urlParams, { data }).map((data: T) => this.model.factory(data));
}

@davidpestana
Copy link
Author

Hi @jonathan-casarrubias thanks for fix..

but upserWithWhere method dont works fine too

when i use swagger exproler this is te CURL chain generated to apply at upserWithWhere

curl 'http://0.0.0.0:3001/api/Prices/upsertWithWhere?where=%7B%22kmRangeId%22%3A%225881789715ef053d73ce1478%22%2C%22serviceId%22%3A%2258817dedb43698003253d89b%22%2C%22rateId%22%3A%225882439cc128bb0034ef8a74%22%7D' -H 'Pragma: no-cache' -H 'Origin: http://0.0.0.0:3001' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: es-ES,es;q=0.8,en;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Cache-Control: no-cache' -H 'Referer: http://0.0.0.0:3001/explorer/' -H 'Connection: keep-alive' --data-binary $'{\n"kmRangeId":"5881789715ef053d73ce1478",\n"serviceId":"58817dedb43698003253d89b",\n"rateId":"5882439cc128bb0034ef8a74",\n"price":1222\n}' --compressed

hoewever when i use SDK to call the CURL chain generated is different.

curl 'http://0.0.0.0:3001/api/Prices/upsertWithWhere' -H 'Pragma: no-cache' -H 'Origin: http://localhost:3000' -H 'where: {"serviceId":"58817dedb43698003253d89b","kmRangeId":"5881789c15ef053d73ce1479","rateId":"5882439cc128bb0034ef8a74"}' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: es-ES,es;q=0.8,en;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json, text/plain, /' -H 'Cache-Control: no-cache' -H 'Referer: http://localhost:3000/' -H 'Connection: keep-alive' --data-binary '{"price":55,"serviceId":"58817dedb43698003253d89b","kmRangeId":"5881789c15ef053d73ce1479","rateId":"5882439cc128bb0034ef8a74"}' --compressed

i call the SDK in Angular2 Component with this code

      this.priceApi.upsertWithWhere(
         {
              serviceId:this.service.id, 
              kmRangeId:this.kmRange.id,
              rateId: this.rate.id
          },
          {
              price:this.price.price,
              serviceId:this.service.id, 
              kmRangeId:this.kmRange.id,
              rateId: this.rate.id
          }      
      ).subscribe(result => console.log(result));

and Loopback returns a server side error...

Error no gestionado para la solicitud POST /api/Prices/upsertWithWhere: AssertionError: The where argument must be an object at Function.DataAccessObject.patchOrCreateWithWhere.DataAccessObject.upsertWithWhere (/home/david/Projects/traqui/api-v2/price-api-v2/node_modules/loopback-datasource-juggler/lib/dao.js:663:3)

maybe i must be a call with another method?

thanks for all

@davidpestana
Copy link
Author

i solved the last issue fixing base.service.ts at line 91

    // Separate where object from url params and add to search query
    if (urlParams.where) {
      headers.append('where', JSON.stringify(urlParams.where));
     // delete urlParams.where;
    
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants