2017-01-23 15:16:48 -06:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Http } from '@angular/http';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
import 'rxjs/add/operator/catch';
|
|
|
|
import 'rxjs/add/operator/map';
|
|
|
|
|
|
|
|
import { AuthService } from '../core';
|
|
|
|
import { AuthHttp } from '../auth';
|
2017-01-30 15:41:14 -06:00
|
|
|
import { RestDataSource, RestExtractor, ResultList } from '../rest';
|
2017-01-23 15:16:48 -06:00
|
|
|
import { VideoAbuse } from './video-abuse.model';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class VideoAbuseService {
|
2017-06-11 08:19:43 -05:00
|
|
|
private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/';
|
2017-01-23 15:16:48 -06:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private authHttp: AuthHttp,
|
|
|
|
private restExtractor: RestExtractor
|
|
|
|
) {}
|
|
|
|
|
2017-01-30 15:41:14 -06:00
|
|
|
getDataSource() {
|
|
|
|
return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse');
|
2017-01-23 15:16:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
reportVideo(id: string, reason: string) {
|
|
|
|
const body = {
|
|
|
|
reason
|
|
|
|
};
|
|
|
|
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse';
|
|
|
|
|
|
|
|
return this.authHttp.post(url, body)
|
|
|
|
.map(this.restExtractor.extractDataBool)
|
|
|
|
.catch((res) => this.restExtractor.handleError(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
private extractVideoAbuses(result: ResultList) {
|
|
|
|
const videoAbuses: VideoAbuse[] = result.data;
|
|
|
|
const totalVideoAbuses = result.total;
|
|
|
|
|
|
|
|
return { videoAbuses, totalVideoAbuses };
|
|
|
|
}
|
|
|
|
}
|