aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/moderation/abuses.ts
blob: 48a51e2b8580910d5e0d47b33a2cfb5448be3155 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import * as request from 'supertest'
import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'

function reportAbuse (
  url: string,
  token: string,
  videoId: number | string,
  reason: string,
  predefinedReasons?: AbusePredefinedReasonsString[],
  startAt?: number,
  endAt?: number,
  specialStatus = 200
) {
  const path = '/api/v1/videos/' + videoId + '/abuse'

  return request(url)
          .post(path)
          .set('Accept', 'application/json')
          .set('Authorization', 'Bearer ' + token)
          .send({ reason, predefinedReasons, startAt, endAt })
          .expect(specialStatus)
}

function getAbusesList (options: {
  url: string
  token: string
  id?: number
  predefinedReason?: AbusePredefinedReasonsString
  search?: string
  state?: AbuseState
  videoIs?: AbuseVideoIs
  searchReporter?: string
  searchReportee?: string
  searchVideo?: string
  searchVideoChannel?: string
}) {
  const {
    url,
    token,
    id,
    predefinedReason,
    search,
    state,
    videoIs,
    searchReporter,
    searchReportee,
    searchVideo,
    searchVideoChannel
  } = options
  const path = '/api/v1/videos/abuse'

  const query = {
    sort: 'createdAt',
    id,
    predefinedReason,
    search,
    state,
    videoIs,
    searchReporter,
    searchReportee,
    searchVideo,
    searchVideoChannel
  }

  return makeGetRequest({
    url,
    path,
    token,
    query,
    statusCodeExpected: 200
  })
}

function updateAbuse (
  url: string,
  token: string,
  videoId: string | number,
  videoAbuseId: number,
  body: AbuseUpdate,
  statusCodeExpected = 204
) {
  const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId

  return makePutBodyRequest({
    url,
    token,
    path,
    fields: body,
    statusCodeExpected
  })
}

function deleteAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) {
  const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId

  return makeDeleteRequest({
    url,
    token,
    path,
    statusCodeExpected
  })
}

// ---------------------------------------------------------------------------

export {
  reportAbuse,
  getAbusesList,
  updateAbuse,
  deleteAbuse
}