2021-07-29 04:27:24 -04:00
|
|
|
import { pick } from '@shared/core-utils'
|
2021-07-06 06:01:59 -04:00
|
|
|
import {
|
|
|
|
AbuseFilter,
|
|
|
|
AbuseMessage,
|
|
|
|
AbusePredefinedReasonsString,
|
|
|
|
AbuseState,
|
|
|
|
AbuseUpdate,
|
|
|
|
AbuseVideoIs,
|
|
|
|
AdminAbuse,
|
2021-07-16 08:27:30 -04:00
|
|
|
HttpStatusCode,
|
2021-07-06 06:01:59 -04:00
|
|
|
ResultList,
|
|
|
|
UserAbuse
|
|
|
|
} from '@shared/models'
|
|
|
|
import { unwrapBody } from '../requests/requests'
|
2021-07-16 08:27:30 -04:00
|
|
|
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
2021-07-06 06:01:59 -04:00
|
|
|
|
|
|
|
export class AbusesCommand extends AbstractCommand {
|
|
|
|
|
|
|
|
report (options: OverrideCommandOptions & {
|
|
|
|
reason: string
|
|
|
|
|
|
|
|
accountId?: number
|
|
|
|
videoId?: number
|
|
|
|
commentId?: number
|
|
|
|
|
|
|
|
predefinedReasons?: AbusePredefinedReasonsString[]
|
|
|
|
|
|
|
|
startAt?: number
|
|
|
|
endAt?: number
|
|
|
|
}) {
|
|
|
|
const path = '/api/v1/abuses'
|
|
|
|
|
|
|
|
const video = options.videoId
|
|
|
|
? {
|
|
|
|
id: options.videoId,
|
|
|
|
startAt: options.startAt,
|
|
|
|
endAt: options.endAt
|
|
|
|
}
|
|
|
|
: undefined
|
|
|
|
|
|
|
|
const comment = options.commentId
|
|
|
|
? { id: options.commentId }
|
|
|
|
: undefined
|
|
|
|
|
|
|
|
const account = options.accountId
|
|
|
|
? { id: options.accountId }
|
|
|
|
: undefined
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
account,
|
|
|
|
video,
|
|
|
|
comment,
|
|
|
|
|
|
|
|
reason: options.reason,
|
|
|
|
predefinedReasons: options.predefinedReasons
|
|
|
|
}
|
|
|
|
|
|
|
|
return unwrapBody<{ abuse: { id: number } }>(this.postBodyRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
fields: body,
|
2021-07-08 04:55:16 -04:00
|
|
|
implicitToken: true,
|
2021-07-06 06:01:59 -04:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
getAdminList (options: OverrideCommandOptions & {
|
|
|
|
start?: number
|
|
|
|
count?: number
|
|
|
|
sort?: string
|
|
|
|
|
|
|
|
id?: number
|
|
|
|
predefinedReason?: AbusePredefinedReasonsString
|
|
|
|
search?: string
|
|
|
|
filter?: AbuseFilter
|
|
|
|
state?: AbuseState
|
|
|
|
videoIs?: AbuseVideoIs
|
|
|
|
searchReporter?: string
|
|
|
|
searchReportee?: string
|
|
|
|
searchVideo?: string
|
|
|
|
searchVideoChannel?: string
|
|
|
|
} = {}) {
|
2021-07-29 04:27:24 -04:00
|
|
|
const toPick: (keyof typeof options)[] = [
|
2021-07-06 06:01:59 -04:00
|
|
|
'count',
|
|
|
|
'filter',
|
|
|
|
'id',
|
|
|
|
'predefinedReason',
|
|
|
|
'search',
|
|
|
|
'searchReportee',
|
|
|
|
'searchReporter',
|
|
|
|
'searchVideo',
|
|
|
|
'searchVideoChannel',
|
|
|
|
'sort',
|
|
|
|
'start',
|
|
|
|
'state',
|
|
|
|
'videoIs'
|
|
|
|
]
|
|
|
|
|
|
|
|
const path = '/api/v1/abuses'
|
|
|
|
|
|
|
|
const defaultQuery = { sort: 'createdAt' }
|
|
|
|
const query = { ...defaultQuery, ...pick(options, toPick) }
|
|
|
|
|
|
|
|
return this.getRequestBody<ResultList<AdminAbuse>>({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
query,
|
2021-07-08 04:55:16 -04:00
|
|
|
implicitToken: true,
|
2021-07-06 06:01:59 -04:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getUserList (options: OverrideCommandOptions & {
|
|
|
|
start?: number
|
|
|
|
count?: number
|
|
|
|
sort?: string
|
|
|
|
|
|
|
|
id?: number
|
|
|
|
search?: string
|
|
|
|
state?: AbuseState
|
|
|
|
}) {
|
2021-07-29 04:27:24 -04:00
|
|
|
const toPick: (keyof typeof options)[] = [
|
2021-07-06 06:01:59 -04:00
|
|
|
'id',
|
|
|
|
'search',
|
|
|
|
'state',
|
|
|
|
'start',
|
|
|
|
'count',
|
|
|
|
'sort'
|
|
|
|
]
|
|
|
|
|
|
|
|
const path = '/api/v1/users/me/abuses'
|
|
|
|
|
|
|
|
const defaultQuery = { sort: 'createdAt' }
|
|
|
|
const query = { ...defaultQuery, ...pick(options, toPick) }
|
|
|
|
|
|
|
|
return this.getRequestBody<ResultList<UserAbuse>>({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
query,
|
2021-07-08 04:55:16 -04:00
|
|
|
implicitToken: true,
|
2021-07-06 06:01:59 -04:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
update (options: OverrideCommandOptions & {
|
|
|
|
abuseId: number
|
|
|
|
body: AbuseUpdate
|
|
|
|
}) {
|
|
|
|
const { abuseId, body } = options
|
|
|
|
const path = '/api/v1/abuses/' + abuseId
|
|
|
|
|
|
|
|
return this.putBodyRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
fields: body,
|
2021-07-08 04:55:16 -04:00
|
|
|
implicitToken: true,
|
2021-07-06 06:01:59 -04:00
|
|
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
delete (options: OverrideCommandOptions & {
|
|
|
|
abuseId: number
|
|
|
|
}) {
|
|
|
|
const { abuseId } = options
|
|
|
|
const path = '/api/v1/abuses/' + abuseId
|
|
|
|
|
2021-07-08 04:55:16 -04:00
|
|
|
return this.deleteRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
implicitToken: true,
|
|
|
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
2021-07-06 06:01:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
listMessages (options: OverrideCommandOptions & {
|
|
|
|
abuseId: number
|
|
|
|
}) {
|
|
|
|
const { abuseId } = options
|
|
|
|
const path = '/api/v1/abuses/' + abuseId + '/messages'
|
|
|
|
|
2021-07-08 04:55:16 -04:00
|
|
|
return this.getRequestBody<ResultList<AbuseMessage>>({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
implicitToken: true,
|
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
2021-07-06 06:01:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteMessage (options: OverrideCommandOptions & {
|
|
|
|
abuseId: number
|
|
|
|
messageId: number
|
|
|
|
}) {
|
|
|
|
const { abuseId, messageId } = options
|
|
|
|
const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId
|
|
|
|
|
2021-07-08 04:55:16 -04:00
|
|
|
return this.deleteRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
implicitToken: true,
|
|
|
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
2021-07-06 06:01:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
addMessage (options: OverrideCommandOptions & {
|
|
|
|
abuseId: number
|
|
|
|
message: string
|
|
|
|
}) {
|
|
|
|
const { abuseId, message } = options
|
|
|
|
const path = '/api/v1/abuses/' + abuseId + '/messages'
|
|
|
|
|
|
|
|
return this.postBodyRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
path,
|
|
|
|
fields: { message },
|
2021-07-08 04:55:16 -04:00
|
|
|
implicitToken: true,
|
2021-07-06 06:01:59 -04:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|