1 import { catchError, map } from 'rxjs/operators'
2 import { HttpClient, HttpParams } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { SortMeta } from 'primeng/components/common/sortmeta'
5 import { Observable } from 'rxjs'
6 import { ResultList, VideoAbuse } from '../../../../../shared'
7 import { environment } from '../../../environments/environment'
8 import { RestExtractor, RestPagination, RestService } from '../rest'
11 export class VideoAbuseService {
12 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
15 private authHttp: HttpClient,
16 private restService: RestService,
17 private restExtractor: RestExtractor
20 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
21 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
23 let params = new HttpParams()
24 params = this.restService.addRestGetParams(params, pagination, sort)
26 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
28 map(res => this.restExtractor.convertResultListDateToHuman(res)),
29 catchError(res => this.restExtractor.handleError(res))
33 reportVideo (id: number, reason: string) {
34 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
39 return this.authHttp.post(url, body)
41 map(this.restExtractor.extractDataBool),
42 catchError(res => this.restExtractor.handleError(res))