Expose Replace* methods - #2316
Conversation
48607b6 to
20238ca
Compare
Replace* methods 3.XReplace* methods
63dec67 to
3d70d65
Compare
|
|
||
| if (options.updateOnPUT) { | ||
| configurableVerbs.replaceById = 'post'; | ||
| configurableVerbs.replaceOrCreate = 'post'; |
There was a problem hiding this comment.
When updateOnPUT is set, then you need to change the HTTP path too, not only the verb.
updateOnPUT=false
replaceById => PUT /:id
replaceOrCreate => PUT /
updateOnPUT=true
replaceById => POST /:id/replaceById
replaceOrCreate => POST /replaceOrCreate
| }); | ||
|
|
||
| if (!options.replaceOnPUT) { | ||
| setRemoting(PersistedModel, 'upsert', { |
There was a problem hiding this comment.
I don't think it's correct to call setRemoting twice for the same method, expecting it to create two HTTP endpoints. The correct way is to provide an array of values in the http property. See how exists defines two HTTP endpoints:
http: [
{ verb: 'get', path: '/:id/exists' },
{ verb: 'head', path: '/:id' },
],We should do the same here. For example:
var upsertEndpoints = [{ verb: 'patch', path: '/' }];
if (!options.replaceOnPUT) {
upsertEndpoints.push( {
verb: 'put',
patch: '/',
});
}
setRemoting('PersistedModel', 'upsert', {
// ...
http: upsertEndpoints
});Or you can use the approach you have in place for replaceOrCreateOptions below, both ways are fine.
81ca747 to
70cec07
Compare
16a0712 to
feb5da1
Compare
|
Hey @bajtos Please note In other words This patch is almost done; I would say 90% is done; could you please confirm you agree with my approach? Thanks Miroslav! |
|
|
||
| // This is just for LB 3.x | ||
| if (options.replaceOnPUT !== false || options.replaceOnPUT === undefined) { | ||
| options.replaceOnPUT = true; |
There was a problem hiding this comment.
Perhaps this could be rewritten as follows?
options.replaceOnPUT = options.replaceOnPUT !== false;| }); | ||
| }); | ||
|
|
||
| describe('With model.settings.replaceOnPUT true' + |
There was a problem hiding this comment.
What is the difference between this test and it('has expected remote methods with model.settings.replaceOnPUT set to true' above? I think it's enough to keep only one of these tests, isn't it?
|
@slnode test please |
|
The CI failures would be passed once this PR#2375 lands. Please see this comment @bajtos I addressed all of your concerns. Could you PTAL again? Also I believe still another PR with some changes needs to be submitted for Thanks :-) |
| .reduce(function(p, c) { | ||
| return p.concat(c); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Also please note I have changed the logic for formatMethod, getFormattedMethodsExcludingRelations, getFormattedScopeMethods,... based on the changes in strong-remoting...
99b9ada to
27a5eb9
Compare
| 'removeById', | ||
| 'count', | ||
| 'prototype.updateAttributes', | ||
| 'prototype.patchAttributes', 'updateAttributes', |
There was a problem hiding this comment.
I think the second item/alias should have prototype. prefix too.
'prototype.patchAttributes', 'prototype.updateAttributes'There was a problem hiding this comment.
I think we either need to fix L627 to prepend prototype. prefix to isStatic:false methods, or change remoting definition of prototype.patchAttributes to specify method alias as prototype.updateAttributes. This depends on how strong-remoting treats aliases of prototype methods, which is something I am not sure about. Could you please check? It is also worth checking how loopback-connector-remote handles these aliases, to ensure code calling myModelInstance.updateAttributes keeps working (assuming the model is attached to a remote-backed datasource).
*Re-mapping `updateAttributes` endpoint to use `PATCH` and `PUT`(configurable) verb *Exposing `replaceById` and `replaceOrCreate` via `POST` and `PUT`(configurable) verb
a9426db to
6502309
Compare
|
@bajtos I addressed your feedback... Please review :-) PS: CI failures do not seem relevant. |
|
@slnode test please |
1 similar comment
|
@slnode test please |
|
LGTM 👏 |
Description:
updateAttributesandupdateOrCreateendpoints to usePATCHverb by default for3.X.replaceByIdandreplaceORCreateviaPUTverbs by default for3.X.model.settings.options.updateOnPUTfor3.X.Note: This patch is for
3.XRelated to #2330 (Implementation for
2.x)Connect to #1979