2020-03-17 14:46:32 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2020-03-18 03:37:39 +01:00
|
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
2020-03-17 14:46:32 +01:00
|
|
|
|
2020-04-08 16:07:13 +02:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { map } from 'rxjs/operators';
|
2020-03-17 14:46:32 +01:00
|
|
|
|
2020-03-25 14:41:22 +01:00
|
|
|
import { environment } from '../../environments/environment'
|
2020-04-08 16:07:13 +02:00
|
|
|
import { apiURL } from '../api-utils'
|
2020-03-25 14:41:22 +01:00
|
|
|
import Folder from '../folder'
|
2020-03-17 14:46:32 +01:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class DbStatusService {
|
|
|
|
private dbStatusUrl = environment.production ? apiURL + 'rest/db/status' : 'api/dbStatus';
|
|
|
|
|
2020-03-26 21:17:03 +01:00
|
|
|
constructor(private http: HttpClient) { }
|
2020-03-17 14:46:32 +01:00
|
|
|
|
2020-03-20 00:01:45 +01:00
|
|
|
getFolderStatus(id: string): Observable<Folder.Status> {
|
2020-03-21 00:44:21 +01:00
|
|
|
let httpOptions: { params: HttpParams };
|
2020-03-18 03:37:39 +01:00
|
|
|
if (id) {
|
2020-03-19 00:39:01 +01:00
|
|
|
httpOptions = {
|
|
|
|
params: new HttpParams().set('folder', id)
|
|
|
|
};
|
2020-03-21 00:44:21 +01:00
|
|
|
} else { }
|
2020-03-18 03:37:39 +01:00
|
|
|
|
2020-03-17 14:46:32 +01:00
|
|
|
return this.http
|
2020-03-20 00:01:45 +01:00
|
|
|
.get<Folder.Status>(this.dbStatusUrl, httpOptions)
|
2020-03-18 03:37:39 +01:00
|
|
|
.pipe(
|
|
|
|
map(res => {
|
2020-03-19 00:39:01 +01:00
|
|
|
// Remove from array in developement
|
|
|
|
// in-memory-web-api returns arrays
|
|
|
|
if (!environment.production) {
|
|
|
|
const a: any = res as any;
|
|
|
|
if (a.length > 0) {
|
2020-03-21 00:44:21 +01:00
|
|
|
res = res[0];
|
2020-03-19 00:39:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-18 03:37:39 +01:00
|
|
|
return res;
|
|
|
|
})
|
2020-03-17 14:46:32 +01:00
|
|
|
);
|
|
|
|
}
|
2020-03-18 03:37:39 +01:00
|
|
|
}
|