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'
12 export class VideoAbuseService {
13 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
16 private authHttp: HttpClient,
17 private restService: RestService,
18 private restExtractor: RestExtractor
21 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
22 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
24 let params = new HttpParams()
25 params = this.restService.addRestGetParams(params, pagination, sort)
27 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
28 .map(res => this.restExtractor.convertResultListDateToHuman(res))
29 .catch(res => this.restExtractor.handleError(res))
32 reportVideo (id: number, reason: string) {
33 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
38 return this.authHttp.post(url, body)
39 .map(this.restExtractor.extractDataBool)
40 .catch(res => this.restExtractor.handleError(res))