mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
use httpclient
This commit is contained in:
parent
30d4adec37
commit
e61542b652
@ -4,8 +4,8 @@ import { environment } from 'src/environments/environment';
|
||||
|
||||
import { Answer } from '../enums/answer.enum';
|
||||
import { Poll } from '../models/poll.model';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { ToastService } from './toast.service';
|
||||
import { LoaderService } from './loader.service';
|
||||
import { Stack } from '../models/stack.model';
|
||||
@ -21,6 +21,7 @@ const apiEndpoints = environment.api.endpoints;
|
||||
})
|
||||
export class ApiService {
|
||||
private static loader: LoaderService;
|
||||
private http: HttpClient;
|
||||
private useDevLocalServer = true;
|
||||
private devLocalServerBaseHref = 'http://localhost:8000/';
|
||||
private axiosInstance: AxiosInstance;
|
||||
@ -59,19 +60,20 @@ export class ApiService {
|
||||
static makeHeaders(bodyContent?: any) {
|
||||
const headerDict = {
|
||||
Charset: 'UTF-8',
|
||||
// 'Content-Type': 'application/json',
|
||||
// Accept: 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
mode: 'no-cors',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Accept,Accept-Language,Content-Language,Content-Type',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
// 'Access-Control-Allow-Origin': '*',
|
||||
};
|
||||
|
||||
const requestOptions = {
|
||||
headers: new HttpHeaders(headerDict),
|
||||
return {
|
||||
headers: headerDict,
|
||||
body: bodyContent,
|
||||
};
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
private static handleError(error): void {
|
||||
@ -110,19 +112,23 @@ export class ApiService {
|
||||
* @param poll
|
||||
* @param vote_stack
|
||||
*/
|
||||
public sendVoteStackOfPoll(poll: Poll, vote_stack: Stack) {
|
||||
public sendVoteStackOfPoll(poll: Poll, vote_stack: Stack): Observable<any> {
|
||||
// api_new_vote_stack POST ANY ANY /api/v1/poll/{id}/answer
|
||||
|
||||
console.log('vote_stack', vote_stack);
|
||||
console.log('this.baseHref', this.baseHref);
|
||||
let headers = ApiService.makeHeaders(vote_stack);
|
||||
let headers = ApiService.makeHeaders();
|
||||
console.log('headers', headers);
|
||||
let url = `${this.baseHref}/${poll.custom_url}/answer`;
|
||||
|
||||
try {
|
||||
return this.axiosInstance.post(`${this.pollsEndpoint}/${poll.custom_url}/answer`, vote_stack, headers);
|
||||
} catch (error) {
|
||||
ApiService.handleError(error);
|
||||
}
|
||||
let axiosconf = {
|
||||
url,
|
||||
method: 'POST',
|
||||
body: vote_stack,
|
||||
headers,
|
||||
};
|
||||
|
||||
return this.http.post(url, vote_stack, headers);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
@ -79,7 +79,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
addVoteStack() {
|
||||
this.api.sendVoteStackOfPoll(this.poll, this.storageService.vote_stack).then((resp) => {
|
||||
this.api.sendVoteStackOfPoll(this.poll, this.storageService.vote_stack).subscribe((resp) => {
|
||||
console.log('resp', resp);
|
||||
|
||||
this.api.getPollBySlug(this.poll.custom_url);
|
||||
|
Loading…
Reference in New Issue
Block a user