]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 | 1 | import * as request from 'supertest' |
d4681c00 | 2 | import { VideoAbuseUpdate } from '../../models/videos/abuse/video-abuse-update.model' |
feb34f6b C |
3 | import { makeDeleteRequest, makePutBodyRequest, makeGetRequest } from '../requests/requests' |
4 | import { VideoAbuseState } from '@shared/models' | |
5 | import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type' | |
0e1dc3e7 | 6 | |
268eebed | 7 | function reportVideoAbuse (url: string, token: string, videoId: number | string, reason: string, specialStatus = 200) { |
0e1dc3e7 C |
8 | const path = '/api/v1/videos/' + videoId + '/abuse' |
9 | ||
10 | return request(url) | |
11 | .post(path) | |
12 | .set('Accept', 'application/json') | |
13 | .set('Authorization', 'Bearer ' + token) | |
14 | .send({ reason }) | |
15 | .expect(specialStatus) | |
16 | } | |
17 | ||
feb34f6b C |
18 | function getVideoAbusesList (options: { |
19 | url: string | |
20 | token: string | |
21 | id?: number | |
22 | search?: string | |
23 | state?: VideoAbuseState | |
24 | videoIs?: VideoAbuseVideoIs | |
25 | searchReporter?: string | |
26 | searchReportee?: string | |
27 | searchVideo?: string | |
28 | searchVideoChannel?: string | |
29 | }) { | |
30 | const { | |
31 | url, | |
32 | token, | |
33 | id, | |
34 | search, | |
35 | state, | |
36 | videoIs, | |
37 | searchReporter, | |
38 | searchReportee, | |
39 | searchVideo, | |
40 | searchVideoChannel | |
41 | } = options | |
0e1dc3e7 C |
42 | const path = '/api/v1/videos/abuse' |
43 | ||
feb34f6b C |
44 | const query = { |
45 | sort: 'createdAt', | |
46 | id, | |
47 | search, | |
48 | state, | |
49 | videoIs, | |
50 | searchReporter, | |
51 | searchReportee, | |
52 | searchVideo, | |
53 | searchVideoChannel | |
54 | } | |
55 | ||
56 | return makeGetRequest({ | |
57 | url, | |
58 | path, | |
59 | token, | |
60 | query, | |
61 | statusCodeExpected: 200 | |
62 | }) | |
0e1dc3e7 C |
63 | } |
64 | ||
268eebed C |
65 | function updateVideoAbuse ( |
66 | url: string, | |
67 | token: string, | |
68 | videoId: string | number, | |
69 | videoAbuseId: number, | |
70 | body: VideoAbuseUpdate, | |
71 | statusCodeExpected = 204 | |
72 | ) { | |
73 | const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId | |
74 | ||
75 | return makePutBodyRequest({ | |
76 | url, | |
77 | token, | |
78 | path, | |
79 | fields: body, | |
80 | statusCodeExpected | |
81 | }) | |
82 | } | |
83 | ||
84 | function deleteVideoAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) { | |
85 | const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId | |
86 | ||
87 | return makeDeleteRequest({ | |
88 | url, | |
89 | token, | |
90 | path, | |
91 | statusCodeExpected | |
92 | }) | |
93 | } | |
94 | ||
0e1dc3e7 C |
95 | // --------------------------------------------------------------------------- |
96 | ||
97 | export { | |
98 | reportVideoAbuse, | |
268eebed C |
99 | getVideoAbusesList, |
100 | updateVideoAbuse, | |
101 | deleteVideoAbuse | |
0e1dc3e7 | 102 | } |