From cc1faf85536e7b337b9f868446e268331dd74462 Mon Sep 17 00:00:00 2001 From: Spectralitree <72747870+Spectralitree@users.noreply.github.com> Date: Sun, 9 Jan 2022 14:59:52 +0100 Subject: [PATCH] feat(api): delete member and group --- src/api/index.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/api/index.ts b/src/api/index.ts index acf826d0..4c0946a9 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -23,6 +23,9 @@ export default class PKAPI { POST_MEMBER: () => `/members`, POST_MEMBER_GROUP: (mid: string, removing: boolean) => !removing ? `/members/${mid}/groups/add` : `/members/${mid}/groups/remove`, POST_GROUP_MEMBER: (gid: string, removing: boolean) => !removing ? `/groups/${gid}/members/add` : `/groups/${gid}/members/remove`, + + DELETE_MEMBER: (mid: string) => `/members/${mid}`, + DELETE_GROUP: (gid: string) => `/groups/${gid}` } baseUrl: string; @@ -143,6 +146,16 @@ export default class PKAPI { } } + async deleteMember(options: {token: string, id: string}) { + var res: AxiosResponse; + try { + res = await this.handle(this.ROUTES.DELETE_MEMBER(options.id), 'DELETE', {token: options.token}); + if (res.status !== 204 ) this.handleErrors(res); + } catch (error) { + throw new Error(error.message); + } + } + async getGroupList(options: {token?: string, id?: any, members?: boolean}) { if (!options.token && !options.id) { throw new Error("Must pass a token or id."); @@ -191,6 +204,16 @@ export default class PKAPI { } } + async deleteGroup(options: {token: string, id: string}) { + var res: AxiosResponse; + try { + res = await this.handle(this.ROUTES.DELETE_GROUP(options.id), 'DELETE', {token: options.token}); + if (res.status !== 204 ) this.handleErrors(res); + } catch (error) { + throw new Error(error.message); + } + } + handleErrors(res: any) { if (res.status === 500) throw new Error("500: Internal server error."); else if (res.status === 401) throw new Error("401: Your token is invalid.");