Skip to content

Commit

Permalink
added decline and accept group join request methods to open cloud gro…
Browse files Browse the repository at this point in the history
…ups api
  • Loading branch information
Cameron Campbell authored and Cameron Campbell committed May 17, 2024
1 parent 906a8c5 commit 6551186
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 43 deletions.
Empty file added docs/pages/index.md
Empty file.
14 changes: 2 additions & 12 deletions src/apis/apiGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ export type ApiMethod<
PrettifiedData extends undefined ? {} : { prettifyFn: (rawData: RawData) => PrettifiedDataOrRawData }
)>

type Overrides = {
cookie?: RobloxCookie,
cloudKey?: string,
oauthToken?: string
}

type ApiMethodResult<
Args extends Record<any, any> | undefined,
RawData, PrettifiedData = RawData,
Expand All @@ -56,6 +50,7 @@ type PrettifiedCursors = ObjectPrettify<{

export type PrettifyData<Input, _ExtendsDate extends boolean = Input extends Date ? true : false> = (
_ExtendsDate extends true ? Input
: Input extends boolean ? boolean
: Input extends Record<any, any> ? ObjectPrettify<Input>
: IsUnion<Input> extends true ? UnionPrettify<Input>
// @ts-ignore | hush hush shawty
Expand All @@ -65,7 +60,6 @@ export type PrettifyData<Input, _ExtendsDate extends boolean = Input extends Dat
)
//////////////////////////////////////////////////////////////////////////////////


// [ Variables ] /////////////////////////////////////////////////////////////////
const config = getConfig()
//////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -161,8 +155,4 @@ type NumberIsLiteral<Num extends number> = (
: [Num] extends [never] ? false
: [Num] extends [string | number] ? true
: false
)



type test = ApiMethodResult<any, any, any>
)
108 changes: 77 additions & 31 deletions src/apis/cloud/groups/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ArrayToUnion, Identifier, ObjectPrettify } from "typeforge"

import type { ApiMethod } from "../../apiGroup"
import { GroupMembers_Filter, GroupMembers_WildcardFilter, PrettifiedGroupInfoData, PrettifiedGroupJoinRequestsData, PrettifiedGroupMembersData, PrettifiedGroupRolesData, PrettifiedGroupShoutData, RawGroupInfoData, RawGroupJoinRequestsData, RawGroupMembersData, RawGroupRolesData, RawGroupShoutData } from "./groups.types"
import { cloneAndMutateObject } from "~/utils/utils"
import { cloneAndMutateObject, dataIsSuccess } from "~/utils/utils"
//////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -63,36 +63,6 @@ export const groupInfo = addApiMethod(async <GroupId extends Identifier>(
}))


/**
* Gets join requests for a group.
* @endpoint GET /v2/groups/{groupId}/join-requests
*
* @param groupId The id of the group to get join requests for.
* @param limit The maximum number of group join requests to return. The service might return fewer than this value. If unspecified, at most 10 group join requests are returned. The maximum value is 20 and higher values are set to 20.
* @param filter This field may be set in order to filter the resources returned.
* @param cursor A page token, received from a previous call, to retrieve a subsequent page.
*
* @example const { data:joinRequests } = await GroupsApi.groupJoinRequests({ groupId: 5850082 })
* @exampleData [{"path":"groups/5850082/join-requests/2655994471","createTime":"2024-05-12T16:32:46.841Z","user":"users/2655994471"}]
* @exampleRawBody {"groupJoinRequests":[{"path":"groups/5850082/join-requests/2655994471","createTime":"2024-05-12T16:32:46.841Z","user":"users/2655994471"}],"nextPageToken":""}
*/
export const groupJoinRequests = addApiMethod(async <GroupId extends Identifier>(
{ groupId, limit, filter:{userId:userIdFilter} = {} as any, cursor }
: { groupId: GroupId, limit?: number, filter?: { userId: Identifier }, cursor?: string }
): ApiMethod<RawGroupJoinRequestsData<GroupId>, PrettifiedGroupJoinRequestsData<GroupId>> => ({
path: `/v2/groups/${groupId}/join-requests`,
method: "GET",
searchParams: { maxPageSize: limit, pageToken: cursor, filter: userIdFilter && `user == 'users/${userIdFilter}'` },
name: "groupJoinRequests",

prettifyFn: ({ groupJoinRequests }) => groupJoinRequests.map(request => cloneAndMutateObject(request, obj => {
obj.createTime = new Date(obj.createTime)
})),

getCursorsFn: ({ nextPageToken }) => [null, nextPageToken]
}))


/**
* Gets join requests for a group.
* @endpoint GET /v2/groups/{groupId}/memberships
Expand Down Expand Up @@ -190,4 +160,80 @@ export const groupShout = addApiMethod(async <GroupId extends Identifier>(
obj.createTime = new Date(obj.createTime)
obj.updateTime = new Date(obj.updateTime)
})
}))


/**
* Gets join requests for a group.
* @endpoint GET /v2/groups/{groupId}/join-requests
*
* @param groupId The id of the group to get join requests for.
* @param limit The maximum number of group join requests to return. The service might return fewer than this value. If unspecified, at most 10 group join requests are returned. The maximum value is 20 and higher values are set to 20.
* @param filter This field may be set in order to filter the resources returned.
* @param cursor A page token, received from a previous call, to retrieve a subsequent page.
*
* @example const { data:joinRequests } = await GroupsApi.groupJoinRequests({ groupId: 5850082 })
* @exampleData [{"path":"groups/5850082/join-requests/2655994471","createTime":"2024-05-12T16:32:46.841Z","user":"users/2655994471"}]
* @exampleRawBody {"groupJoinRequests":[{"path":"groups/5850082/join-requests/2655994471","createTime":"2024-05-12T16:32:46.841Z","user":"users/2655994471"}],"nextPageToken":""}
*/
export const groupJoinRequests = addApiMethod(async <GroupId extends Identifier>(
{ groupId, limit, filter:{userId:userIdFilter} = {} as any, cursor }
: { groupId: GroupId, limit?: number, filter?: { userId: Identifier }, cursor?: string }
): ApiMethod<RawGroupJoinRequestsData<GroupId>, PrettifiedGroupJoinRequestsData<GroupId>> => ({
path: `/v2/groups/${groupId}/join-requests`,
method: "GET",
searchParams: { maxPageSize: limit, pageToken: cursor, filter: userIdFilter && `user == 'users/${userIdFilter}'` },
name: "groupJoinRequests",

prettifyFn: ({ groupJoinRequests }) => groupJoinRequests.map(request => cloneAndMutateObject(request, obj => {
obj.createTime = new Date(obj.createTime)
})),

getCursorsFn: ({ nextPageToken }) => [null, nextPageToken]
}))


/**
* Accepts a group join request.
* @endpoint POST /v2/groups/{groupId}/join-requests/{userId}:accept
*
* @param groupId The id of the group to accept a join request for.
* @param userId The id of the user to accept into the group.
*
* @example const { data:success } = await GroupsApi.acceptGroupJoinRequest({ groupId: 5850082, userId: 2655994471 });
* @exampleData true
* @exampleRawBody {}
*/
export const acceptGroupJoinRequest = addApiMethod(async <GroupId extends Identifier>(
{ groupId, userId }: { groupId: GroupId, userId: Identifier }
): ApiMethod<{}, boolean> => ({
method: "POST",
path: `/v2/groups/${groupId}/join-requests/${userId}:accept`,
body: {},
name: "acceptGroupJoinRequest",

prettifyFn: (rawData) => dataIsSuccess(rawData)
}))


/**
* Declines a group join request.
* @endpoint POST /v2/groups/{groupId}/join-requests/{userId}:decline
*
* @param groupId The id of the group to decline a join request for.
* @param userId The id of the user to decline from the group.
*
* @example const { data:success } = await GroupsApi.declineGroupJoinRequest({ groupId: 5850082, userId: 2655994471 });
* @exampleData true
* @exampleRawBody {}
*/
export const declineGroupJoinRequest = addApiMethod(async <GroupId extends Identifier>(
{ groupId, userId }: { groupId: GroupId, userId: Identifier }
): ApiMethod<{}, boolean> => ({
method: "POST",
path: `/v2/groups/${groupId}/join-requests/${userId}:decline`,
body: {},
name: "declineGroupJoinRequest",

prettifyFn: (rawData) => dataIsSuccess(rawData)
}))

0 comments on commit 6551186

Please sign in to comment.