feat(api): delete member and group
This commit is contained in:
parent
72de7910d2
commit
cc1faf8553
@ -23,6 +23,9 @@ export default class PKAPI {
|
|||||||
POST_MEMBER: () => `/members`,
|
POST_MEMBER: () => `/members`,
|
||||||
POST_MEMBER_GROUP: (mid: string, removing: boolean) => !removing ? `/members/${mid}/groups/add` : `/members/${mid}/groups/remove`,
|
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`,
|
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;
|
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}) {
|
async getGroupList(options: {token?: string, id?: any, members?: boolean}) {
|
||||||
if (!options.token && !options.id) {
|
if (!options.token && !options.id) {
|
||||||
throw new Error("Must pass a token or 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) {
|
handleErrors(res: any) {
|
||||||
if (res.status === 500) throw new Error("500: Internal server error.");
|
if (res.status === 500) throw new Error("500: Internal server error.");
|
||||||
else if (res.status === 401) throw new Error("401: Your token is invalid.");
|
else if (res.status === 401) throw new Error("401: Your token is invalid.");
|
||||||
|
Loading…
Reference in New Issue
Block a user