HttpPatch ignored by Angular request










2















I'm having a strange issue. I'm working on a bulk edit feature for my application. Whenever a user updates a field, my form autosaves. Once the autosave event triggers, I loop through a set of similar set of user selected records with the intent to make the same change there.



For example, I might have the form loaded for plan id:4, but also want the edits to apply to records with IDs of 2, 3, 7, 10. So lets say I change the projectName field to "A Great Project". My desired result would be to update all five records to have the projectname field to "A great Project".



However, even though I loop through each record, I only hit the service once, and thats for the original plan (in my example 4). Everything else just dies off. I still see the changes in my state, and can follow them all through.



This is my save after typing event on a container/component



autoSave(save: changes: Plan, field: string, value: any) 

this.planContext.getEnabled().forEach(x =>
x.plan[save.field] = save.value;
console.info(x.plan);
this.autoSavePlan(x.plan, x.plan.id);
);


autoSavePlan(changes: Plan, id: number)
this.store.dispatch(new PlanActions.Edit( plan: id: id, changes: changes ));



I have the following effect



 @Effect()
editPlan$: Observable<Action> = this.actions$
.ofType<Edit>(PlanActionTypes.Edit).pipe(
switchMap(action => this.planService.editPlan(action.payload.plan)), //Last Line of code for server break point for failing records.
map((plan: any) =>
console.log(plan);
return new EditSuccess( id: plan.id, changes: plan);
),
catchError(err =>
toastr.error(`An error has occurred. Please reload the page before making any other changes.`);
console.error(err);
return of(new EditFail(err));
)
);


Service Call:



editPlan(plan: Update<Plan>) : Observable<Plan> 
this.log("Editing a Plan");

return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plan.changes, this.httpPatchOptions);



PlansController



[Authorize]
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Plan> plan)

//Breakpoint hit only once
if (!ModelState.IsValid)

return BadRequest(ModelState);

//... do stuff



EDIT1



User Story:
As a user, I would like to be able to edit multiple plans at once. I should be able to update a plan field with a single value, and have that change also applied to other plan records that I have selected for bulk editing.



Expected Result:
I update a field in my form. I should see a service call for each plan I have selected, and prove that the change is being applied to all plans.



Current result:
I run through a loop submitting httppatchs for each plan. I only ever see changes applied to one of them. If I attempt to follow the code via breakpoints, eventually I hit F10 and the chrome debugger loses context for all but one of the plans. This is consistently the plast plan in my list. There is no error logged, no indication of what happened. Likewise, the breakpoint on my service is only ever triggered once.



EDIT2



Leaving the above for context. My original problem was a fundamental issue with the way i was thinking about observables. Because I was updating the observable four times in the autosave function, it makes sense that anything subscribing to it wouldnt work as i anticipated. As we know, you only get the most recent object. Which is why only one update call would occur.



After tinkering I was able to recreate all the above methods with Update. That resolved part of the issue.



This works as expected, but fails to meet my user requirement:



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);



This does not work. I would expect to see two service calls. The service is never called. I never even hit the breakpoint in the PlanController.



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var x = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[0].id + ")", plans[0].changes, this.httpPatchOptions);
var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);










share|improve this question
























  • I read your question 10 times I still don't know what you're asking. Please clarify what the expected result is and what is the actual result, and also if you can provide a stackblitz that works or doesn't work.

    – Aviad P.
    Nov 14 '18 at 22:17











  • @AviadP.just start at edit1.

    – Seth
    Nov 15 '18 at 13:30















2















I'm having a strange issue. I'm working on a bulk edit feature for my application. Whenever a user updates a field, my form autosaves. Once the autosave event triggers, I loop through a set of similar set of user selected records with the intent to make the same change there.



For example, I might have the form loaded for plan id:4, but also want the edits to apply to records with IDs of 2, 3, 7, 10. So lets say I change the projectName field to "A Great Project". My desired result would be to update all five records to have the projectname field to "A great Project".



However, even though I loop through each record, I only hit the service once, and thats for the original plan (in my example 4). Everything else just dies off. I still see the changes in my state, and can follow them all through.



This is my save after typing event on a container/component



autoSave(save: changes: Plan, field: string, value: any) 

this.planContext.getEnabled().forEach(x =>
x.plan[save.field] = save.value;
console.info(x.plan);
this.autoSavePlan(x.plan, x.plan.id);
);


autoSavePlan(changes: Plan, id: number)
this.store.dispatch(new PlanActions.Edit( plan: id: id, changes: changes ));



I have the following effect



 @Effect()
editPlan$: Observable<Action> = this.actions$
.ofType<Edit>(PlanActionTypes.Edit).pipe(
switchMap(action => this.planService.editPlan(action.payload.plan)), //Last Line of code for server break point for failing records.
map((plan: any) =>
console.log(plan);
return new EditSuccess( id: plan.id, changes: plan);
),
catchError(err =>
toastr.error(`An error has occurred. Please reload the page before making any other changes.`);
console.error(err);
return of(new EditFail(err));
)
);


Service Call:



editPlan(plan: Update<Plan>) : Observable<Plan> 
this.log("Editing a Plan");

return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plan.changes, this.httpPatchOptions);



PlansController



[Authorize]
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Plan> plan)

//Breakpoint hit only once
if (!ModelState.IsValid)

return BadRequest(ModelState);

//... do stuff



EDIT1



User Story:
As a user, I would like to be able to edit multiple plans at once. I should be able to update a plan field with a single value, and have that change also applied to other plan records that I have selected for bulk editing.



Expected Result:
I update a field in my form. I should see a service call for each plan I have selected, and prove that the change is being applied to all plans.



Current result:
I run through a loop submitting httppatchs for each plan. I only ever see changes applied to one of them. If I attempt to follow the code via breakpoints, eventually I hit F10 and the chrome debugger loses context for all but one of the plans. This is consistently the plast plan in my list. There is no error logged, no indication of what happened. Likewise, the breakpoint on my service is only ever triggered once.



EDIT2



Leaving the above for context. My original problem was a fundamental issue with the way i was thinking about observables. Because I was updating the observable four times in the autosave function, it makes sense that anything subscribing to it wouldnt work as i anticipated. As we know, you only get the most recent object. Which is why only one update call would occur.



After tinkering I was able to recreate all the above methods with Update. That resolved part of the issue.



This works as expected, but fails to meet my user requirement:



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);



This does not work. I would expect to see two service calls. The service is never called. I never even hit the breakpoint in the PlanController.



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var x = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[0].id + ")", plans[0].changes, this.httpPatchOptions);
var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);










share|improve this question
























  • I read your question 10 times I still don't know what you're asking. Please clarify what the expected result is and what is the actual result, and also if you can provide a stackblitz that works or doesn't work.

    – Aviad P.
    Nov 14 '18 at 22:17











  • @AviadP.just start at edit1.

    – Seth
    Nov 15 '18 at 13:30













2












2








2








I'm having a strange issue. I'm working on a bulk edit feature for my application. Whenever a user updates a field, my form autosaves. Once the autosave event triggers, I loop through a set of similar set of user selected records with the intent to make the same change there.



For example, I might have the form loaded for plan id:4, but also want the edits to apply to records with IDs of 2, 3, 7, 10. So lets say I change the projectName field to "A Great Project". My desired result would be to update all five records to have the projectname field to "A great Project".



However, even though I loop through each record, I only hit the service once, and thats for the original plan (in my example 4). Everything else just dies off. I still see the changes in my state, and can follow them all through.



This is my save after typing event on a container/component



autoSave(save: changes: Plan, field: string, value: any) 

this.planContext.getEnabled().forEach(x =>
x.plan[save.field] = save.value;
console.info(x.plan);
this.autoSavePlan(x.plan, x.plan.id);
);


autoSavePlan(changes: Plan, id: number)
this.store.dispatch(new PlanActions.Edit( plan: id: id, changes: changes ));



I have the following effect



 @Effect()
editPlan$: Observable<Action> = this.actions$
.ofType<Edit>(PlanActionTypes.Edit).pipe(
switchMap(action => this.planService.editPlan(action.payload.plan)), //Last Line of code for server break point for failing records.
map((plan: any) =>
console.log(plan);
return new EditSuccess( id: plan.id, changes: plan);
),
catchError(err =>
toastr.error(`An error has occurred. Please reload the page before making any other changes.`);
console.error(err);
return of(new EditFail(err));
)
);


Service Call:



editPlan(plan: Update<Plan>) : Observable<Plan> 
this.log("Editing a Plan");

return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plan.changes, this.httpPatchOptions);



PlansController



[Authorize]
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Plan> plan)

//Breakpoint hit only once
if (!ModelState.IsValid)

return BadRequest(ModelState);

//... do stuff



EDIT1



User Story:
As a user, I would like to be able to edit multiple plans at once. I should be able to update a plan field with a single value, and have that change also applied to other plan records that I have selected for bulk editing.



Expected Result:
I update a field in my form. I should see a service call for each plan I have selected, and prove that the change is being applied to all plans.



Current result:
I run through a loop submitting httppatchs for each plan. I only ever see changes applied to one of them. If I attempt to follow the code via breakpoints, eventually I hit F10 and the chrome debugger loses context for all but one of the plans. This is consistently the plast plan in my list. There is no error logged, no indication of what happened. Likewise, the breakpoint on my service is only ever triggered once.



EDIT2



Leaving the above for context. My original problem was a fundamental issue with the way i was thinking about observables. Because I was updating the observable four times in the autosave function, it makes sense that anything subscribing to it wouldnt work as i anticipated. As we know, you only get the most recent object. Which is why only one update call would occur.



After tinkering I was able to recreate all the above methods with Update. That resolved part of the issue.



This works as expected, but fails to meet my user requirement:



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);



This does not work. I would expect to see two service calls. The service is never called. I never even hit the breakpoint in the PlanController.



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var x = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[0].id + ")", plans[0].changes, this.httpPatchOptions);
var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);










share|improve this question
















I'm having a strange issue. I'm working on a bulk edit feature for my application. Whenever a user updates a field, my form autosaves. Once the autosave event triggers, I loop through a set of similar set of user selected records with the intent to make the same change there.



For example, I might have the form loaded for plan id:4, but also want the edits to apply to records with IDs of 2, 3, 7, 10. So lets say I change the projectName field to "A Great Project". My desired result would be to update all five records to have the projectname field to "A great Project".



However, even though I loop through each record, I only hit the service once, and thats for the original plan (in my example 4). Everything else just dies off. I still see the changes in my state, and can follow them all through.



This is my save after typing event on a container/component



autoSave(save: changes: Plan, field: string, value: any) 

this.planContext.getEnabled().forEach(x =>
x.plan[save.field] = save.value;
console.info(x.plan);
this.autoSavePlan(x.plan, x.plan.id);
);


autoSavePlan(changes: Plan, id: number)
this.store.dispatch(new PlanActions.Edit( plan: id: id, changes: changes ));



I have the following effect



 @Effect()
editPlan$: Observable<Action> = this.actions$
.ofType<Edit>(PlanActionTypes.Edit).pipe(
switchMap(action => this.planService.editPlan(action.payload.plan)), //Last Line of code for server break point for failing records.
map((plan: any) =>
console.log(plan);
return new EditSuccess( id: plan.id, changes: plan);
),
catchError(err =>
toastr.error(`An error has occurred. Please reload the page before making any other changes.`);
console.error(err);
return of(new EditFail(err));
)
);


Service Call:



editPlan(plan: Update<Plan>) : Observable<Plan> 
this.log("Editing a Plan");

return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plan.changes, this.httpPatchOptions);



PlansController



[Authorize]
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Plan> plan)

//Breakpoint hit only once
if (!ModelState.IsValid)

return BadRequest(ModelState);

//... do stuff



EDIT1



User Story:
As a user, I would like to be able to edit multiple plans at once. I should be able to update a plan field with a single value, and have that change also applied to other plan records that I have selected for bulk editing.



Expected Result:
I update a field in my form. I should see a service call for each plan I have selected, and prove that the change is being applied to all plans.



Current result:
I run through a loop submitting httppatchs for each plan. I only ever see changes applied to one of them. If I attempt to follow the code via breakpoints, eventually I hit F10 and the chrome debugger loses context for all but one of the plans. This is consistently the plast plan in my list. There is no error logged, no indication of what happened. Likewise, the breakpoint on my service is only ever triggered once.



EDIT2



Leaving the above for context. My original problem was a fundamental issue with the way i was thinking about observables. Because I was updating the observable four times in the autosave function, it makes sense that anything subscribing to it wouldnt work as i anticipated. As we know, you only get the most recent object. Which is why only one update call would occur.



After tinkering I was able to recreate all the above methods with Update. That resolved part of the issue.



This works as expected, but fails to meet my user requirement:



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);



This does not work. I would expect to see two service calls. The service is never called. I never even hit the breakpoint in the PlanController.



editBulkPlan(plans: Update<Plan>): Observable<Plan> 

var x = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[0].id + ")", plans[0].changes, this.httpPatchOptions);
var y = this.http.patch<Plan>(this.odataUrl + "Plans(" + plans[1].id + ")", plans[1].changes, this.httpPatchOptions);

return y;

//return this.http.patch<Plan>(this.odataUrl + "Plans(" + plan.id + ")", plans.changes, this.httpPatchOptions);







angular typescript odata






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 13:40







Seth

















asked Nov 14 '18 at 21:14









SethSeth

2871222




2871222












  • I read your question 10 times I still don't know what you're asking. Please clarify what the expected result is and what is the actual result, and also if you can provide a stackblitz that works or doesn't work.

    – Aviad P.
    Nov 14 '18 at 22:17











  • @AviadP.just start at edit1.

    – Seth
    Nov 15 '18 at 13:30

















  • I read your question 10 times I still don't know what you're asking. Please clarify what the expected result is and what is the actual result, and also if you can provide a stackblitz that works or doesn't work.

    – Aviad P.
    Nov 14 '18 at 22:17











  • @AviadP.just start at edit1.

    – Seth
    Nov 15 '18 at 13:30
















I read your question 10 times I still don't know what you're asking. Please clarify what the expected result is and what is the actual result, and also if you can provide a stackblitz that works or doesn't work.

– Aviad P.
Nov 14 '18 at 22:17





I read your question 10 times I still don't know what you're asking. Please clarify what the expected result is and what is the actual result, and also if you can provide a stackblitz that works or doesn't work.

– Aviad P.
Nov 14 '18 at 22:17













@AviadP.just start at edit1.

– Seth
Nov 15 '18 at 13:30





@AviadP.just start at edit1.

– Seth
Nov 15 '18 at 13:30












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308810%2fhttppatch-ignored-by-angular-request%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308810%2fhttppatch-ignored-by-angular-request%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo