46 lines
1.3 KiB
TypeScript
46 lines
1.3 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 HistoryService {
|
|
protected url: string;
|
|
|
|
constructor(private http: HttpClient) {
|
|
const api_url = inject(API_URL);
|
|
this.url = `${api_url}/history`;
|
|
}
|
|
|
|
public getHistory(options?: Options): Observable<any> {
|
|
let params = new HttpParams();
|
|
if (options) {
|
|
if (options.envelopeId)
|
|
params = params.set('envelopeId', options.envelopeId);
|
|
if (options.referenceType != null)
|
|
params = params.set('referenceType', options.referenceType);
|
|
if (options.userReference)
|
|
params = params.set('userReference', options.userReference);
|
|
if (options.withReceiver)
|
|
params = params.set('withReceiver', options.withReceiver);
|
|
if (options.withSender)
|
|
params = params.set('withSender', options.withSender);
|
|
}
|
|
return this.http.get(this.url, { params });
|
|
}
|
|
|
|
public async getHistoryAsync(options?: Options): Promise<any> {
|
|
return firstValueFrom(this.getHistory(options));
|
|
}
|
|
}
|
|
|
|
class Options {
|
|
envelopeId?: number;
|
|
userReference?: string;
|
|
referenceType: number | null = null;
|
|
withSender?: boolean;
|
|
withReceiver?: boolean;
|
|
} |