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/api'
5 import { Observable } from 'rxjs'
6 import { ResultList, VideoAbuse, VideoAbuseUpdate, VideoAbuseState } 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 (options: {
21 pagination: RestPagination,
24 }): Observable<ResultList<VideoAbuse>> {
25 const { pagination, sort, search } = options
26 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
28 let params = new HttpParams()
29 params = this.restService.addRestGetParams(params, pagination, sort)
32 const filters = this.restService.parseQueryStringFilter(search, {
37 if (v === 'accepted') return VideoAbuseState.ACCEPTED
38 if (v === 'pending') return VideoAbuseState.PENDING
39 if (v === 'rejected') return VideoAbuseState.REJECTED
47 if (v === 'deleted') return v
48 if (v === 'blacklisted') return v
53 searchReporter: { prefix: 'reporter:' },
54 searchReportee: { prefix: 'reportee:' }
57 params = this.restService.addObjectParams(params, filters)
60 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
62 catchError(res => this.restExtractor.handleError(res))
66 reportVideo (id: number, reason: string) {
67 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
68 const body = { reason }
70 return this.authHttp.post(url, body)
72 map(this.restExtractor.extractDataBool),
73 catchError(res => this.restExtractor.handleError(res))
77 updateVideoAbuse (videoAbuse: VideoAbuse, abuseUpdate: VideoAbuseUpdate) {
78 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
80 return this.authHttp.put(url, abuseUpdate)
82 map(this.restExtractor.extractDataBool),
83 catchError(res => this.restExtractor.handleError(res))
87 removeVideoAbuse (videoAbuse: VideoAbuse) {
88 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
90 return this.authHttp.delete(url)
92 map(this.restExtractor.extractDataBool),
93 catchError(res => this.restExtractor.handleError(res))