Commits
Alisa Ismailati authored 442426bb2e7
1 + | import { Injectable } from '@angular/core'; |
2 + | import { RequestService } from './request.service'; |
3 + | import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; |
4 + | import { ObjectCacheService } from '../cache/object-cache.service'; |
5 + | import { HALEndpointService } from '../shared/hal-endpoint.service'; |
6 + | import { IdentifiableDataService } from './base/identifiable-data.service'; |
7 + | import { dataService } from './base/data-service.decorator'; |
8 + | import { NotifyRequestsStatus } from '../../item-page/simple/notify-requests-status/notify-requests-status.model'; |
9 + | import { NOTIFYREQUEST} from '../../item-page/simple/notify-requests-status/notify-requests-status.resource-type'; |
10 + | import { Observable, map, take, tap } from 'rxjs'; |
11 + | import { RemoteData } from './remote-data'; |
12 + | import { GetRequest } from './request.models'; |
13 + | |
14 + | |
15 + | @Injectable() |
16 + | @dataService(NOTIFYREQUEST) |
17 + | export class NotifyRequestsStatusDataService extends IdentifiableDataService<NotifyRequestsStatus> { |
18 + | |
19 + | private notifyRequestLink = 'notifyrequests'; |
20 + | |
21 + | constructor( |
22 + | protected requestService: RequestService, |
23 + | protected rdbService: RemoteDataBuildService, |
24 + | protected objectCache: ObjectCacheService, |
25 + | protected halService: HALEndpointService, |
26 + | protected rdb: RemoteDataBuildService, |
27 + | ) { |
28 + | super('ldn', requestService, rdbService, objectCache, halService); |
29 + | } |
30 + | |
31 + | /** |
32 + | * Retrieves the status of notify requests for a specific item. |
33 + | * @param itemUuid The UUID of the item. |
34 + | * @returns An Observable that emits the remote data containing the notify requests status. |
35 + | */ |
36 + | getNotifyRequestsStatus(itemUuid: string): Observable<RemoteData<NotifyRequestsStatus>> { |
37 + | const href$ = this.halService.getEndpoint(this.notifyRequestLink).pipe( |
38 + | tap((url: string) => console.log('url', url) ), |
39 + | map((url: string) => url + '/' + itemUuid), |
40 + | ); |
41 + | |
42 + | href$.pipe(take(1)).subscribe((url: string) => { |
43 + | const request = new GetRequest(this.requestService.generateRequestId(), url); |
44 + | this.requestService.send(request, true); |
45 + | }); |
46 + | |
47 + | return this.rdb.buildFromHref(href$); |
48 + | } |
49 + | } |