From edbc9325462ddf4536775871ebc25e06f46612d1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Jul 2020 15:05:51 +0200 Subject: Add server API to abuse messages --- shared/extra-utils/moderation/abuses.ts | 86 +++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) (limited to 'shared/extra-utils/moderation/abuses.ts') diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts index 62af9556e..7db75cebb 100644 --- a/shared/extra-utils/moderation/abuses.ts +++ b/shared/extra-utils/moderation/abuses.ts @@ -54,7 +54,7 @@ function reportAbuse (options: { }) } -function getAbusesList (options: { +function getAdminAbusesList (options: { url: string token: string @@ -117,6 +117,48 @@ function getAbusesList (options: { }) } +function getUserAbusesList (options: { + url: string + token: string + + start?: number + count?: number + sort?: string + + id?: number + search?: string + state?: AbuseState +}) { + const { + url, + token, + start, + count, + sort, + id, + search, + state + } = options + const path = '/api/v1/users/me/abuses' + + const query = { + id, + search, + state, + start, + count, + sort: sort || 'createdAt' + } + + return makeGetRequest({ + url, + path, + token, + query, + statusCodeExpected: 200 + }) +} + function updateAbuse ( url: string, token: string, @@ -146,11 +188,49 @@ function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExp }) } +function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = 200) { + const path = '/api/v1/abuses/' + abuseId + '/messages' + + return makeGetRequest({ + url, + token, + path, + statusCodeExpected + }) +} + +function deleteAbuseMessage (url: string, token: string, abuseId: number, messageId: number, statusCodeExpected = 204) { + const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId + + return makeDeleteRequest({ + url, + token, + path, + statusCodeExpected + }) +} + +function addAbuseMessage (url: string, token: string, abuseId: number, message: string, statusCodeExpected = 200) { + const path = '/api/v1/abuses/' + abuseId + '/messages' + + return makePostBodyRequest({ + url, + token, + path, + fields: { message }, + statusCodeExpected + }) +} + // --------------------------------------------------------------------------- export { reportAbuse, - getAbusesList, + getAdminAbusesList, updateAbuse, - deleteAbuse + deleteAbuse, + getUserAbusesList, + listAbuseMessages, + deleteAbuseMessage, + addAbuseMessage } -- cgit v1.2.3