diff --git a/src/api/index.ts b/src/api/index.ts index e4a57f68..8588aa73 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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` : ""}`, PATCH_SYSTEM: () => `/systems/@me`, + PATCH_GROUP: (gid: string) => `/groups/${gid}`, POST_MEMBER: () => `/members` } @@ -139,6 +140,20 @@ export default class PKAPI { 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) { if (res.status === 500) throw new Error("500: Internal server error."); else if (res.status === 401) throw new Error("401: Your token is invalid.");