]>
Commit | Line | Data |
---|---|---|
11ac88de C |
1 | import { Injectable } from '@angular/core'; |
2 | import { Http } from '@angular/http'; | |
3 | import { Observable } from 'rxjs/Observable'; | |
4 | import 'rxjs/add/operator/catch'; | |
5 | import 'rxjs/add/operator/map'; | |
6 | ||
7 | import { AuthService } from '../core'; | |
8 | import { AuthHttp } from '../auth'; | |
9 | import { RestExtractor, ResultList } from '../rest'; | |
10 | import { VideoAbuse } from './video-abuse.model'; | |
11 | ||
12 | @Injectable() | |
13 | export class VideoAbuseService { | |
14 | private static BASE_VIDEO_ABUSE_URL = '/api/v1/videos/'; | |
15 | ||
16 | constructor( | |
17 | private authHttp: AuthHttp, | |
18 | private restExtractor: RestExtractor | |
19 | ) {} | |
20 | ||
21 | getVideoAbuses() { | |
22 | return this.authHttp.get(VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse') | |
23 | .map(this.restExtractor.extractDataList) | |
24 | .map(this.extractVideoAbuses) | |
25 | } | |
26 | ||
27 | reportVideo(id: string, reason: string) { | |
28 | const body = { | |
29 | reason | |
30 | }; | |
31 | const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'; | |
32 | ||
33 | return this.authHttp.post(url, body) | |
34 | .map(this.restExtractor.extractDataBool) | |
35 | .catch((res) => this.restExtractor.handleError(res)); | |
36 | } | |
37 | ||
38 | private extractVideoAbuses(result: ResultList) { | |
39 | const videoAbuses: VideoAbuse[] = result.data; | |
40 | const totalVideoAbuses = result.total; | |
41 | ||
42 | return { videoAbuses, totalVideoAbuses }; | |
43 | } | |
44 | } |