|
@@ -2,13 +2,16 @@ import { Observable } from 'rxjs';
|
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
|
import { Injectable } from '@angular/core';
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
-import { environment } from 'src/environments/environment.development';
|
|
|
+import { environment } from 'src/environments/environment.prod';
|
|
|
|
|
|
@Injectable({
|
|
|
providedIn: 'root',
|
|
|
})
|
|
|
export class ApiService {
|
|
|
- constructor(private readonly http: HttpClient, private readonly translate: TranslateService) {}
|
|
|
+ constructor(
|
|
|
+ private readonly http: HttpClient,
|
|
|
+ private readonly translate: TranslateService
|
|
|
+ ) {}
|
|
|
|
|
|
getUploadHeaders() {
|
|
|
const token: string | null = localStorage.getItem('token') || null;
|
|
@@ -18,7 +21,9 @@ export class ApiService {
|
|
|
|
|
|
if (token) {
|
|
|
return {
|
|
|
- headers: new HttpHeaders().set('lang', language).set('Authorization', 'Bearer ' + token),
|
|
|
+ headers: new HttpHeaders()
|
|
|
+ .set('lang', language)
|
|
|
+ .set('Authorization', 'Bearer ' + token),
|
|
|
};
|
|
|
} else {
|
|
|
return {
|
|
@@ -28,37 +33,47 @@ export class ApiService {
|
|
|
}
|
|
|
|
|
|
public get<TResponse>(type: string, params?: any): Observable<TResponse> {
|
|
|
- return this.http.get<TResponse>(environment.baseURL + type, {
|
|
|
+ return this.http.get<TResponse>(environment.BASE_URL + type, {
|
|
|
params: { ...params },
|
|
|
...this.getUploadHeaders(),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public post<TInput, TResponse>(type: string, data: TInput): Observable<TResponse> {
|
|
|
+ public post<TInput, TResponse>(
|
|
|
+ type: string,
|
|
|
+ data: TInput
|
|
|
+ ): Observable<TResponse> {
|
|
|
// if (type === 'File/Upload') {
|
|
|
// return this.http.post<TResponse>(environment.BASE_FILE_URL + type, data, {
|
|
|
// ...this.getUploadHeaders(),
|
|
|
// });
|
|
|
// }
|
|
|
- return this.http.post<TResponse>(environment.baseURL + type, data ?? {}, {
|
|
|
+ return this.http.post<TResponse>(environment.BASE_URL + type, data ?? {}, {
|
|
|
...this.getUploadHeaders(),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public put<TInput, TResponse>(type: string, data: TInput, params?: any): Observable<TResponse> {
|
|
|
- return this.http.put<TResponse>(environment.baseURL + type, data, {
|
|
|
+ public put<TInput, TResponse>(
|
|
|
+ type: string,
|
|
|
+ data: TInput,
|
|
|
+ params?: any
|
|
|
+ ): Observable<TResponse> {
|
|
|
+ return this.http.put<TResponse>(environment.BASE_URL + type, data, {
|
|
|
params: { ...params },
|
|
|
...this.getUploadHeaders(),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public delete<TInput, TResponse>(type: string, id?: TInput): Observable<TResponse> {
|
|
|
+ public delete<TInput, TResponse>(
|
|
|
+ type: string,
|
|
|
+ id?: TInput
|
|
|
+ ): Observable<TResponse> {
|
|
|
if (id) {
|
|
|
- return this.http.delete<TResponse>(environment.baseURL + type + id, {
|
|
|
+ return this.http.delete<TResponse>(environment.BASE_URL + type + id, {
|
|
|
...this.getUploadHeaders(),
|
|
|
});
|
|
|
} else {
|
|
|
- return this.http.delete<TResponse>(environment.baseURL + type, {
|
|
|
+ return this.http.delete<TResponse>(environment.BASE_URL + type, {
|
|
|
...this.getUploadHeaders(),
|
|
|
});
|
|
|
}
|