1 import { pick } from '@shared/core-utils'
5 AbusePredefinedReasonsString,
13 } from '@shared/models'
14 import { unwrapBody } from '../requests/requests'
15 import { AbstractCommand, OverrideCommandOptions } from '../shared'
17 export class AbusesCommand extends AbstractCommand {
19 report (options: OverrideCommandOptions & {
26 predefinedReasons?: AbusePredefinedReasonsString[]
31 const path = '/api/v1/abuses'
33 const video = options.videoId
36 startAt: options.startAt,
41 const comment = options.commentId
42 ? { id: options.commentId }
45 const account = options.accountId
46 ? { id: options.accountId }
54 reason: options.reason,
55 predefinedReasons: options.predefinedReasons
58 return unwrapBody<{ abuse: { id: number } }>(this.postBodyRequest({
64 defaultExpectedStatus: HttpStatusCode.OK_200
68 getAdminList (options: OverrideCommandOptions & {
74 predefinedReason?: AbusePredefinedReasonsString
78 videoIs?: AbuseVideoIs
79 searchReporter?: string
80 searchReportee?: string
82 searchVideoChannel?: string
84 const toPick: (keyof typeof options)[] = [
100 const path = '/api/v1/abuses'
102 const defaultQuery = { sort: 'createdAt' }
103 const query = { ...defaultQuery, ...pick(options, toPick) }
105 return this.getRequestBody<ResultList<AdminAbuse>>({
111 defaultExpectedStatus: HttpStatusCode.OK_200
115 getUserList (options: OverrideCommandOptions & {
124 const toPick: (keyof typeof options)[] = [
133 const path = '/api/v1/users/me/abuses'
135 const defaultQuery = { sort: 'createdAt' }
136 const query = { ...defaultQuery, ...pick(options, toPick) }
138 return this.getRequestBody<ResultList<UserAbuse>>({
144 defaultExpectedStatus: HttpStatusCode.OK_200
148 update (options: OverrideCommandOptions & {
152 const { abuseId, body } = options
153 const path = '/api/v1/abuses/' + abuseId
155 return this.putBodyRequest({
161 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
165 delete (options: OverrideCommandOptions & {
168 const { abuseId } = options
169 const path = '/api/v1/abuses/' + abuseId
171 return this.deleteRequest({
176 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
180 listMessages (options: OverrideCommandOptions & {
183 const { abuseId } = options
184 const path = '/api/v1/abuses/' + abuseId + '/messages'
186 return this.getRequestBody<ResultList<AbuseMessage>>({
191 defaultExpectedStatus: HttpStatusCode.OK_200
195 deleteMessage (options: OverrideCommandOptions & {
199 const { abuseId, messageId } = options
200 const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId
202 return this.deleteRequest({
207 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
211 addMessage (options: OverrideCommandOptions & {
215 const { abuseId, message } = options
216 const path = '/api/v1/abuses/' + abuseId + '/messages'
218 return this.postBodyRequest({
224 defaultExpectedStatus: HttpStatusCode.OK_200