From b23155172af27ded064099bac6d0e85709929676 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 20 May 2021 14:23:57 +0200 Subject: [PATCH] send votestack and reload poll config --- src/app/core/services/api.service.ts | 11 ++--------- .../consultation/consultation.component.ts | 16 ++++------------ 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index e9801514..0f3604ec 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -117,7 +117,7 @@ export class ApiService { * @param poll * @param vote_stack */ - public sendNewVoteStackOfPoll(poll: Poll, vote_stack: Stack): Observable { + public sendNewVoteStackOfPoll(poll: Poll, vote_stack: Stack): Promise { // api_new_vote_stack POST ANY ANY /api/v1/poll/{id}/answer console.log('vote_stack', vote_stack); @@ -133,14 +133,7 @@ export class ApiService { headers, }; - return this.http.post(url, vote_stack, { - headers: { - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Accept,Accept-Language,Content-Language,Content-Type', - }, - }); + return this.axiosInstance.post(url, vote_stack); } ////////// diff --git a/src/app/features/consultation/consultation.component.ts b/src/app/features/consultation/consultation.component.ts index c9c20aec..76478595 100644 --- a/src/app/features/consultation/consultation.component.ts +++ b/src/app/features/consultation/consultation.component.ts @@ -88,19 +88,11 @@ export class ConsultationComponent implements OnInit, OnDestroy { } addVoteStack(): void { - this.api.sendNewVoteStackOfPoll(this.poll, this.storageService.vote_stack).subscribe((resp) => { - console.log('sendNewVoteStackOfPoll resp', resp); + this.toastService.display('envoi du vote ....'); + this.api.sendNewVoteStackOfPoll(this.poll, this.storageService.vote_stack).then((resp) => { + console.log('resp', resp); - this.toastService.display('vote ajouté', 'success'); - - if (resp) { - const response: Promise = this.api.getPollByCustomUrl(this.poll.custom_url); - response.then((res: Poll | undefined) => { - this.pollService._poll.next(res); - }); - } else { - this.toastService.display('erreur à la réception du nouveau vote', 'error'); - } + this.pollService.loadPollBycustom_url(this.poll.custom_url); }); }