]>
Commit | Line | Data |
---|---|---|
d592e0a9 | 1 | import { HttpClient, HttpParams } from '@angular/common/http' |
63c4db6d C |
2 | import { Injectable } from '@angular/core' |
3 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
df98563e C |
4 | import 'rxjs/add/operator/catch' |
5 | import 'rxjs/add/operator/map' | |
d592e0a9 | 6 | import { Observable } from 'rxjs/Observable' |
63c4db6d | 7 | import { ResultList, VideoAbuse } from '../../../../../shared' |
d592e0a9 C |
8 | import { RestExtractor, RestPagination, RestService } from '../rest' |
9 | import { Utils } from '../utils' | |
63c4db6d | 10 | import { environment } from '../../../environments/environment' |
11ac88de C |
11 | |
12 | @Injectable() | |
13 | export class VideoAbuseService { | |
63c4db6d | 14 | private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/' |
11ac88de | 15 | |
df98563e | 16 | constructor ( |
d592e0a9 C |
17 | private authHttp: HttpClient, |
18 | private restService: RestService, | |
11ac88de C |
19 | private restExtractor: RestExtractor |
20 | ) {} | |
21 | ||
d592e0a9 C |
22 | getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> { |
23 | const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse' | |
24 | ||
25 | let params = new HttpParams() | |
26 | params = this.restService.addRestGetParams(params, pagination, sort) | |
27 | ||
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)) | |
11ac88de C |
32 | } |
33 | ||
0a6658fd | 34 | reportVideo (id: number, reason: string) { |
d592e0a9 | 35 | const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse' |
11ac88de C |
36 | const body = { |
37 | reason | |
df98563e | 38 | } |
11ac88de C |
39 | |
40 | return this.authHttp.post(url, body) | |
41 | .map(this.restExtractor.extractDataBool) | |
d592e0a9 | 42 | .catch(res => this.restExtractor.handleError(res)) |
11ac88de C |
43 | } |
44 | ||
d592e0a9 C |
45 | private formatVideoAbuse (videoAbuse: VideoAbuse) { |
46 | return Object.assign(videoAbuse, { | |
47 | createdAt: Utils.dateToHuman(videoAbuse.createdAt) | |
48 | }) | |
11ac88de | 49 | } |
d592e0a9 | 50 | |
11ac88de | 51 | } |