From 57f6896f67cfc570cf3605dd94b0778101b2d9b9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Jul 2020 10:57:04 +0200 Subject: Implement abuses check params --- shared/extra-utils/moderation/abuses.ts | 88 +++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 27 deletions(-) (limited to 'shared/extra-utils') diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts index 48a51e2b8..1af703f92 100644 --- a/shared/extra-utils/moderation/abuses.ts +++ b/shared/extra-utils/moderation/abuses.ts @@ -1,25 +1,57 @@ -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) +import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' +import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' + +function reportAbuse (options: { + url: string + token: string + + reason: string + + accountId?: number + videoId?: number + commentId?: number + + predefinedReasons?: AbusePredefinedReasonsString[] + + startAt?: number + endAt?: number + + statusCodeExpected?: 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 makePostBodyRequest({ + url: options.url, + path, + token: options.token, + + fields: body, + statusCodeExpected: options.statusCodeExpected || 200 + }) } function getAbusesList (options: { @@ -28,6 +60,7 @@ function getAbusesList (options: { id?: number predefinedReason?: AbusePredefinedReasonsString search?: string + filter?: AbuseFilter, state?: AbuseState videoIs?: AbuseVideoIs searchReporter?: string @@ -41,6 +74,7 @@ function getAbusesList (options: { id, predefinedReason, search, + filter, state, videoIs, searchReporter, @@ -48,7 +82,7 @@ function getAbusesList (options: { searchVideo, searchVideoChannel } = options - const path = '/api/v1/videos/abuse' + const path = '/api/v1/abuses' const query = { sort: 'createdAt', @@ -56,6 +90,7 @@ function getAbusesList (options: { predefinedReason, search, state, + filter, videoIs, searchReporter, searchReportee, @@ -75,12 +110,11 @@ function getAbusesList (options: { function updateAbuse ( url: string, token: string, - videoId: string | number, - videoAbuseId: number, + abuseId: number, body: AbuseUpdate, statusCodeExpected = 204 ) { - const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId + const path = '/api/v1/abuses/' + abuseId return makePutBodyRequest({ url, @@ -91,8 +125,8 @@ function updateAbuse ( }) } -function deleteAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) { - const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId +function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) { + const path = '/api/v1/abuses/' + abuseId return makeDeleteRequest({ url, -- cgit v1.2.3