]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video-abuse/video-abuse.service.ts
Upgrade Angular first step
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-abuse / video-abuse.service.ts
1 import { HttpClient, HttpParams } from '@angular/common/http'
2 import { Injectable } from '@angular/core'
3 import { SortMeta } from 'primeng/components/common/sortmeta'
4 import 'rxjs/add/operator/catch'
5 import 'rxjs/add/operator/map'
6 import { Observable } from 'rxjs/Observable'
7 import { ResultList, VideoAbuse } from '../../../../../shared'
8 import { environment } from '../../../environments/environment'
9 import { RestExtractor, RestPagination, RestService } from '../rest'
10
11 @Injectable()
12 export class VideoAbuseService {
13 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
14
15 constructor (
16 private authHttp: HttpClient,
17 private restService: RestService,
18 private restExtractor: RestExtractor
19 ) {}
20
21 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
22 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
23
24 let params = new HttpParams()
25 params = this.restService.addRestGetParams(params, pagination, sort)
26
27 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
28 .map(res => this.restExtractor.convertResultListDateToHuman(res))
29 .catch(res => this.restExtractor.handleError(res))
30 }
31
32 reportVideo (id: number, reason: string) {
33 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
34 const body = {
35 reason
36 }
37
38 return this.authHttp.post(url, body)
39 .map(this.restExtractor.extractDataBool)
40 .catch(res => this.restExtractor.handleError(res))
41 }
42 }