diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-01 16:05:30 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-07-10 14:02:41 +0200 |
commit | d95d15598847c7f020aa056e7e6e0c02d2bbf732 (patch) | |
tree | a8a593f1269688caf9e5f99559996f346290fec5 /client/src/app/shared/shared-moderation/abuse.service.ts | |
parent | 72493e44e9b455a04c4f093ed6c6ffa300b98d8b (diff) | |
download | PeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.tar.gz PeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.tar.zst PeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.zip |
Use 3 tables to represent abuses
Diffstat (limited to 'client/src/app/shared/shared-moderation/abuse.service.ts')
-rw-r--r-- | client/src/app/shared/shared-moderation/abuse.service.ts | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-moderation/abuse.service.ts b/client/src/app/shared/shared-moderation/abuse.service.ts new file mode 100644 index 000000000..f45018d5c --- /dev/null +++ b/client/src/app/shared/shared-moderation/abuse.service.ts | |||
@@ -0,0 +1,98 @@ | |||
1 | import { omit } from 'lodash-es' | ||
2 | import { SortMeta } from 'primeng/api' | ||
3 | import { Observable } from 'rxjs' | ||
4 | import { catchError, map } from 'rxjs/operators' | ||
5 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
6 | import { Injectable } from '@angular/core' | ||
7 | import { RestExtractor, RestPagination, RestService } from '@app/core' | ||
8 | import { AbuseUpdate, ResultList, Abuse, AbuseCreate, AbuseState } from '@shared/models' | ||
9 | import { environment } from '../../../environments/environment' | ||
10 | |||
11 | @Injectable() | ||
12 | export class AbuseService { | ||
13 | private static BASE_ABUSE_URL = environment.apiUrl + '/api/v1/abuses' | ||
14 | |||
15 | constructor ( | ||
16 | private authHttp: HttpClient, | ||
17 | private restService: RestService, | ||
18 | private restExtractor: RestExtractor | ||
19 | ) {} | ||
20 | |||
21 | getAbuses (options: { | ||
22 | pagination: RestPagination, | ||
23 | sort: SortMeta, | ||
24 | search?: string | ||
25 | }): Observable<ResultList<Abuse>> { | ||
26 | const { pagination, sort, search } = options | ||
27 | const url = AbuseService.BASE_ABUSE_URL + 'abuse' | ||
28 | |||
29 | let params = new HttpParams() | ||
30 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
31 | |||
32 | if (search) { | ||
33 | const filters = this.restService.parseQueryStringFilter(search, { | ||
34 | id: { prefix: '#' }, | ||
35 | state: { | ||
36 | prefix: 'state:', | ||
37 | handler: v => { | ||
38 | if (v === 'accepted') return AbuseState.ACCEPTED | ||
39 | if (v === 'pending') return AbuseState.PENDING | ||
40 | if (v === 'rejected') return AbuseState.REJECTED | ||
41 | |||
42 | return undefined | ||
43 | } | ||
44 | }, | ||
45 | videoIs: { | ||
46 | prefix: 'videoIs:', | ||
47 | handler: v => { | ||
48 | if (v === 'deleted') return v | ||
49 | if (v === 'blacklisted') return v | ||
50 | |||
51 | return undefined | ||
52 | } | ||
53 | }, | ||
54 | searchReporter: { prefix: 'reporter:' }, | ||
55 | searchReportee: { prefix: 'reportee:' }, | ||
56 | predefinedReason: { prefix: 'tag:' } | ||
57 | }) | ||
58 | |||
59 | params = this.restService.addObjectParams(params, filters) | ||
60 | } | ||
61 | |||
62 | return this.authHttp.get<ResultList<Abuse>>(url, { params }) | ||
63 | .pipe( | ||
64 | catchError(res => this.restExtractor.handleError(res)) | ||
65 | ) | ||
66 | } | ||
67 | |||
68 | reportVideo (parameters: AbuseCreate) { | ||
69 | const url = AbuseService.BASE_ABUSE_URL | ||
70 | |||
71 | const body = omit(parameters, [ 'id' ]) | ||
72 | |||
73 | return this.authHttp.post(url, body) | ||
74 | .pipe( | ||
75 | map(this.restExtractor.extractDataBool), | ||
76 | catchError(res => this.restExtractor.handleError(res)) | ||
77 | ) | ||
78 | } | ||
79 | |||
80 | updateAbuse (abuse: Abuse, abuseUpdate: AbuseUpdate) { | ||
81 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id | ||
82 | |||
83 | return this.authHttp.put(url, abuseUpdate) | ||
84 | .pipe( | ||
85 | map(this.restExtractor.extractDataBool), | ||
86 | catchError(res => this.restExtractor.handleError(res)) | ||
87 | ) | ||
88 | } | ||
89 | |||
90 | removeAbuse (abuse: Abuse) { | ||
91 | const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id | ||
92 | |||
93 | return this.authHttp.delete(url) | ||
94 | .pipe( | ||
95 | map(this.restExtractor.extractDataBool), | ||
96 | catchError(res => this.restExtractor.handleError(res)) | ||
97 | ) | ||
98 | }} | ||