diff options
Diffstat (limited to 'client/src/app/shared/video-abuse')
-rw-r--r-- | client/src/app/shared/video-abuse/video-abuse.service.ts | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts index 636a02084..984581114 100644 --- a/client/src/app/shared/video-abuse/video-abuse.service.ts +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts | |||
@@ -1,42 +1,53 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { Http } from '@angular/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Observable } from 'rxjs/Observable' | ||
4 | import 'rxjs/add/operator/catch' | 3 | import 'rxjs/add/operator/catch' |
5 | import 'rxjs/add/operator/map' | 4 | import 'rxjs/add/operator/map' |
5 | import { Observable } from 'rxjs/Observable' | ||
6 | |||
7 | import { SortMeta } from 'primeng/primeng' | ||
6 | 8 | ||
7 | import { AuthService } from '../core' | 9 | import { AuthService } from '../core' |
8 | import { AuthHttp } from '../auth' | 10 | import { RestExtractor, RestPagination, RestService } from '../rest' |
9 | import { RestDataSource, RestExtractor, ResultList } from '../rest' | 11 | import { Utils } from '../utils' |
10 | import { VideoAbuse } from '../../../../../shared' | 12 | import { ResultList, VideoAbuse } from '../../../../../shared' |
11 | 13 | ||
12 | @Injectable() | 14 | @Injectable() |
13 | export class VideoAbuseService { | 15 | export class VideoAbuseService { |
14 | private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/' | 16 | private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/' |
15 | 17 | ||
16 | constructor ( | 18 | constructor ( |
17 | private authHttp: AuthHttp, | 19 | private authHttp: HttpClient, |
20 | private restService: RestService, | ||
18 | private restExtractor: RestExtractor | 21 | private restExtractor: RestExtractor |
19 | ) {} | 22 | ) {} |
20 | 23 | ||
21 | getDataSource () { | 24 | getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> { |
22 | return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse') | 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)) | ||
23 | } | 34 | } |
24 | 35 | ||
25 | reportVideo (id: number, reason: string) { | 36 | reportVideo (id: number, reason: string) { |
37 | const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse' | ||
26 | const body = { | 38 | const body = { |
27 | reason | 39 | reason |
28 | } | 40 | } |
29 | const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse' | ||
30 | 41 | ||
31 | return this.authHttp.post(url, body) | 42 | return this.authHttp.post(url, body) |
32 | .map(this.restExtractor.extractDataBool) | 43 | .map(this.restExtractor.extractDataBool) |
33 | .catch((res) => this.restExtractor.handleError(res)) | 44 | .catch(res => this.restExtractor.handleError(res)) |
34 | } | 45 | } |
35 | 46 | ||
36 | private extractVideoAbuses (result: ResultList) { | 47 | private formatVideoAbuse (videoAbuse: VideoAbuse) { |
37 | const videoAbuses: VideoAbuse[] = result.data | 48 | return Object.assign(videoAbuse, { |
38 | const totalVideoAbuses = result.total | 49 | createdAt: Utils.dateToHuman(videoAbuse.createdAt) |
39 | 50 | }) | |
40 | return { videoAbuses, totalVideoAbuses } | ||
41 | } | 51 | } |
52 | |||
42 | } | 53 | } |