feat: patch group method
This commit is contained in:
parent
3a24910e22
commit
87be16fceb
@ -17,6 +17,7 @@ export default class PKAPI {
|
|||||||
GET_GROUP_LIST: (sid?: string, members?: boolean) => `${sid ? `/systems/${sid}/groups` : `/systems/@me/groups`}` + `${members ? `?with_members=true` : ""}`,
|
GET_GROUP_LIST: (sid?: string, members?: boolean) => `${sid ? `/systems/${sid}/groups` : `/systems/@me/groups`}` + `${members ? `?with_members=true` : ""}`,
|
||||||
|
|
||||||
PATCH_SYSTEM: () => `/systems/@me`,
|
PATCH_SYSTEM: () => `/systems/@me`,
|
||||||
|
PATCH_GROUP: (gid: string) => `/groups/${gid}`,
|
||||||
|
|
||||||
POST_MEMBER: () => `/members`
|
POST_MEMBER: () => `/members`
|
||||||
}
|
}
|
||||||
@ -139,6 +140,20 @@ export default class PKAPI {
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async patchGroup(options: {token: string, id: any, data: any}) {
|
||||||
|
var body = new Group(options.data);
|
||||||
|
var group: Group;
|
||||||
|
var res: AxiosResponse;
|
||||||
|
try {
|
||||||
|
res = await this.handle(this.ROUTES.PATCH_GROUP(options.id), 'PATCH', {token: options.token, body: body});
|
||||||
|
if (res.status === 200) group = new Group(res.data);
|
||||||
|
else this.handleErrors(res);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
}
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
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