33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
import { Observable, firstValueFrom } from 'rxjs';
|
|
import { API_URL } from '../tokens/index';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class EnvelopeService {
|
|
protected url: string;
|
|
|
|
constructor(private http: HttpClient) {
|
|
const api_url = inject(API_URL);
|
|
this.url = `${api_url}/envelope`;
|
|
}
|
|
|
|
public getEnvelope(options?: { min_status?: number; max_status?: number; ignore_status?: number[] }): Observable<any> {
|
|
let params = new HttpParams();
|
|
if (options) {
|
|
if (options.min_status)
|
|
params = params.set('min_status', options.min_status.toString());
|
|
if (options.max_status)
|
|
params = params.set('max_status', options.max_status.toString());
|
|
if (options.ignore_status)
|
|
params = params.set('ignore_status', options.ignore_status.join(','));
|
|
}
|
|
return this.http.get(this.url, { params });
|
|
}
|
|
|
|
public async getEnvelopeAsync(options?: { min_status?: number; max_status?: number; ignore_status?: number[] }): Promise<any> {
|
|
return await firstValueFrom(this.getEnvelope(options));
|
|
}
|
|
} |