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