]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video-abuse/video-abuse.service.ts
Client: replace simple tables by ng2 smart table component
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-abuse / video-abuse.service.ts
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 { RestDataSource, 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 getDataSource() {
22 return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse');
23 }
24
25 reportVideo(id: string, reason: string) {
26 const body = {
27 reason
28 };
29 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse';
30
31 return this.authHttp.post(url, body)
32 .map(this.restExtractor.extractDataBool)
33 .catch((res) => this.restExtractor.handleError(res));
34 }
35
36 private extractVideoAbuses(result: ResultList) {
37 const videoAbuses: VideoAbuse[] = result.data;
38 const totalVideoAbuses = result.total;
39
40 return { videoAbuses, totalVideoAbuses };
41 }
42 }