]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/video/video-ownership.service.ts
Fix comment in PR template
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video-ownership.service.ts
1 import { SortMeta } from 'primeng/api'
2 import { Observable } from 'rxjs'
3 import { catchError, map } from 'rxjs/operators'
4 import { HttpClient, HttpParams } from '@angular/common/http'
5 import { Injectable } from '@angular/core'
6 import { RestExtractor, RestPagination, RestService } from '@app/core'
7 import { ResultList, VideoChangeOwnership, VideoChangeOwnershipAccept, VideoChangeOwnershipCreate } from '@shared/models'
8 import { environment } from '../../../../environments/environment'
9
10 @Injectable()
11 export class VideoOwnershipService {
12 private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/'
13
14 constructor (
15 private authHttp: HttpClient,
16 private restService: RestService,
17 private restExtractor: RestExtractor
18 ) {
19 }
20
21 changeOwnership (id: number, username: string) {
22 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership'
23 const body: VideoChangeOwnershipCreate = {
24 username
25 }
26
27 return this.authHttp.post(url, body)
28 .pipe(
29 map(this.restExtractor.extractDataBool),
30 catchError(res => this.restExtractor.handleError(res))
31 )
32 }
33
34 getOwnershipChanges (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoChangeOwnership>> {
35 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership'
36
37 let params = new HttpParams()
38 params = this.restService.addRestGetParams(params, pagination, sort)
39
40 return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params })
41 .pipe(
42 map(res => this.restExtractor.convertResultListDateToHuman(res)),
43 catchError(res => this.restExtractor.handleError(res))
44 )
45 }
46
47 acceptOwnership (id: number, input: VideoChangeOwnershipAccept) {
48 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept'
49 return this.authHttp.post(url, input)
50 .pipe(
51 map(this.restExtractor.extractDataBool),
52 catchError(this.restExtractor.handleError)
53 )
54 }
55
56 refuseOwnership (id: number) {
57 const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse'
58 return this.authHttp.post(url, {})
59 .pipe(
60 map(this.restExtractor.extractDataBool),
61 catchError(this.restExtractor.handleError)
62 )
63 }
64 }