2017-06-16 07:32:15 -05: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'
|
2017-01-23 15:16:48 -06:00
|
|
|
|
2017-06-16 07:32:15 -05:00
|
|
|
import { AuthService } from '../core'
|
|
|
|
import { AuthHttp } from '../auth'
|
|
|
|
import { RestDataSource, RestExtractor, ResultList } from '../rest'
|
2017-06-17 04:28:11 -05:00
|
|
|
import { VideoAbuse } from '../../../../../shared'
|
2017-01-23 15:16:48 -06:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class VideoAbuseService {
|
2017-06-16 07:32:15 -05:00
|
|
|
private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/'
|
2017-01-23 15:16:48 -06:00
|
|
|
|
2017-06-16 07:32:15 -05:00
|
|
|
constructor (
|
2017-01-23 15:16:48 -06:00
|
|
|
private authHttp: AuthHttp,
|
|
|
|
private restExtractor: RestExtractor
|
|
|
|
) {}
|
|
|
|
|
2017-06-16 07:32:15 -05:00
|
|
|
getDataSource () {
|
|
|
|
return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse')
|
2017-01-23 15:16:48 -06:00
|
|
|
}
|
|
|
|
|
2017-07-11 09:01:56 -05:00
|
|
|
reportVideo (id: number, reason: string) {
|
2017-01-23 15:16:48 -06:00
|
|
|
const body = {
|
|
|
|
reason
|
2017-06-16 07:32:15 -05:00
|
|
|
}
|
|
|
|
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
|
2017-01-23 15:16:48 -06:00
|
|
|
|
|
|
|
return this.authHttp.post(url, body)
|
|
|
|
.map(this.restExtractor.extractDataBool)
|
2017-06-16 07:32:15 -05:00
|
|
|
.catch((res) => this.restExtractor.handleError(res))
|
2017-01-23 15:16:48 -06:00
|
|
|
}
|
|
|
|
|
2017-06-16 07:32:15 -05:00
|
|
|
private extractVideoAbuses (result: ResultList) {
|
|
|
|
const videoAbuses: VideoAbuse[] = result.data
|
|
|
|
const totalVideoAbuses = result.total
|
2017-01-23 15:16:48 -06:00
|
|
|
|
2017-06-16 07:32:15 -05:00
|
|
|
return { videoAbuses, totalVideoAbuses }
|
2017-01-23 15:16:48 -06:00
|
|
|
}
|
|
|
|
}
|