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 { RestExtractor, RestPagination, RestService } from '../rest'
9 import { Utils } from '../utils'
10 import { environment } from '../../../environments/environment'
13 export class VideoAbuseService {
14 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
17 private authHttp: HttpClient,
18 private restService: RestService,
19 private restExtractor: RestExtractor
22 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
23 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
25 let params = new HttpParams()
26 params = this.restService.addRestGetParams(params, pagination, sort)
28 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
29 .map(res => this.restExtractor.convertResultListDateToHuman(res))
30 .map(res => this.restExtractor.applyToResultListData(res, this.formatVideoAbuse.bind(this)))
31 .catch(res => this.restExtractor.handleError(res))
34 reportVideo (id: number, reason: string) {
35 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
40 return this.authHttp.post(url, body)
41 .map(this.restExtractor.extractDataBool)
42 .catch(res => this.restExtractor.handleError(res))
45 private formatVideoAbuse (videoAbuse: VideoAbuse) {
46 return Object.assign(videoAbuse, {
47 createdAt: Utils.dateToHuman(videoAbuse.createdAt)