diff --git a/src/app/provider/helper/http.service.ts b/src/app/provider/helper/http.service.ts index f4dabaa..fe41c86 100644 --- a/src/app/provider/helper/http.service.ts +++ b/src/app/provider/helper/http.service.ts @@ -1,20 +1,22 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable, NgZone } from '@angular/core'; -import { Capacitor } from '@capacitor/core'; -import { HTTP, HTTPResponse } from '@ionic-native/http/ngx'; -import { from, Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; -import { runInZone } from '../../utils/run-in-zone.operator'; +import { HttpClient } from "@angular/common/http"; +import { Injectable, NgZone } from "@angular/core"; +import { Capacitor } from "@capacitor/core"; +import { HTTP, HTTPResponse } from "@ionic-native/http/ngx"; +import { from, Observable } from "rxjs"; +import { map } from "rxjs/operators"; +import { runInZone } from "../../utils/run-in-zone.operator"; @Injectable({ - providedIn: 'root' + providedIn: "root", }) export class HttpService { - - private develop: boolean; // L'indicateur de plateforme web ou native - constructor(private readonly nativeHttp: HTTP, private readonly developHttp: HttpClient, private readonly zone: NgZone) { + constructor( + private readonly nativeHttp: HTTP, + private readonly developHttp: HttpClient, + private readonly zone: NgZone + ) { this.develop = !Capacitor.isNativePlatform(); } @@ -31,10 +33,10 @@ export class HttpService { } else { get$ = this.nativeGet(url); } + console.warn("Ready to calll ", url); return get$; } - post(url: string, body?: any, ignoreCors?: boolean): Observable { let post$; if (this.develop || !ignoreCors) { @@ -45,25 +47,28 @@ export class HttpService { return post$; } - - /** * La methode qui get en natif * @param url L'url a get */ private nativeGet(url: string) { - return from(this.nativeHttp.get(url, {}, {})) - .pipe( - runInZone(this.zone), - map((data: HTTPResponse) => JSON.parse(data.data)) - ); + const headers: any = { + "Content-Type": "application/json", + }; + headers["Accept"] = "application/json"; + return from(this.nativeHttp.get(url, {}, headers)).pipe( + runInZone(this.zone), + map((data: HTTPResponse) => { + return JSON.parse(data.data); + }) + ); } /** * La methode qui call en broswer * @param url l'url a get */ private developGet(url: string) { - return this.developHttp.get(url,); + return this.developHttp.get(url); } /** @@ -72,11 +77,10 @@ export class HttpService { * @param body le body a poster */ private nativePost(url: string, body?: any) { - - return from(this.nativeHttp.post(url, body, {})) - .pipe( - runInZone(this.zone), - map((data: HTTPResponse) => JSON.parse(data.data))); + return from(this.nativeHttp.post(url, body, {})).pipe( + runInZone(this.zone), + map((data: HTTPResponse) => JSON.parse(data.data)) + ); } /** * La methode qui call en broswer @@ -86,6 +90,4 @@ export class HttpService { private developPost(url: string, body?: any) { return this.developHttp.post(url, body); } - - }