]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video-abuse/video-abuse.service.ts
Update client according to new model paths
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-abuse / video-abuse.service.ts
CommitLineData
db400f44 1import { catchError, map } from 'rxjs/operators'
d592e0a9 2import { HttpClient, HttpParams } from '@angular/common/http'
63c4db6d
C
3import { Injectable } from '@angular/core'
4import { SortMeta } from 'primeng/components/common/sortmeta'
db400f44 5import { Observable } from 'rxjs'
efc9e845 6import { ResultList, VideoAbuse, VideoAbuseUpdate } from '../../../../../shared'
63c4db6d 7import { environment } from '../../../environments/environment'
61bbc727 8import { RestExtractor, RestPagination, RestService } from '../rest'
11ac88de
C
9
10@Injectable()
11export class VideoAbuseService {
63c4db6d 12 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
11ac88de 13
df98563e 14 constructor (
d592e0a9
C
15 private authHttp: HttpClient,
16 private restService: RestService,
11ac88de
C
17 private restExtractor: RestExtractor
18 ) {}
19
d592e0a9
C
20 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
21 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
22
23 let params = new HttpParams()
24 params = this.restService.addRestGetParams(params, pagination, sort)
25
26 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
db400f44
C
27 .pipe(
28 map(res => this.restExtractor.convertResultListDateToHuman(res)),
29 catchError(res => this.restExtractor.handleError(res))
30 )
11ac88de
C
31 }
32
0a6658fd 33 reportVideo (id: number, reason: string) {
d592e0a9 34 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
11ac88de
C
35 const body = {
36 reason
df98563e 37 }
11ac88de
C
38
39 return this.authHttp.post(url, body)
db400f44
C
40 .pipe(
41 map(this.restExtractor.extractDataBool),
42 catchError(res => this.restExtractor.handleError(res))
43 )
11ac88de 44 }
efc9e845
C
45
46 updateVideoAbuse (videoAbuse: VideoAbuse, abuseUpdate: VideoAbuseUpdate) {
47 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
48
49 return this.authHttp.put(url, abuseUpdate)
50 .pipe(
51 map(this.restExtractor.extractDataBool),
52 catchError(res => this.restExtractor.handleError(res))
53 )
54 }
55
56 removeVideoAbuse (videoAbuse: VideoAbuse) {
57 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
58
59 return this.authHttp.delete(url)
60 .pipe(
61 map(this.restExtractor.extractDataBool),
62 catchError(res => this.restExtractor.handleError(res))
63 )
64 }}