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 { 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 { return firstValueFrom(this.getHistory(options)); } } class Options { envelopeId?: number; userReference?: string; referenceType: number | null = null; withSender?: boolean; withReceiver?: boolean; }