Skip to content

Commit

Permalink
feat(api,api-sdk): update return response to void
Browse files Browse the repository at this point in the history
  • Loading branch information
waddaboo committed Dec 20, 2024
1 parent f9faf9e commit 6a36eaf
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 78 deletions.
20 changes: 3 additions & 17 deletions apps/api/src/app/groups/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ export class GroupsController {
@Post("/members/:member")
@ApiBody({ type: AddMemberToGroupsDto })
@ApiHeader({ name: "x-api-key", required: true })
@ApiCreatedResponse({ isArray: true, type: Group })
@ApiOperation({
description:
"Adds a member to multiple groups. Requires an API Key in the headers or a valid session."
Expand All @@ -390,37 +389,24 @@ export class GroupsController {
@Body() dto: AddMemberToGroupsDto,
@Headers() headers: Headers,
@Req() req: Request
) {
let groups = []
const groupsToResponseDTO = []

): Promise<void | any> {
const apiKey = headers["x-api-key"] as string

if (apiKey) {
groups = await this.groupsService.addMemberToGroupsWithAPIKey(
await this.groupsService.addMemberToGroupsWithAPIKey(
dto.groupIds,
memberId,
apiKey
)
} else if (req.session.adminId) {
groups = await this.groupsService.addMemberToGroupsManually(
await this.groupsService.addMemberToGroupsManually(
dto.groupIds,
memberId,
req.session.adminId
)
} else {
throw new NotImplementedException()
}

for await (const group of groups) {
const fingerprint = await this.groupsService.getFingerprint(
group.id
)

groupsToResponseDTO.push(mapGroupToResponseDTO(group, fingerprint))
}

return groupsToResponseDTO
}

@Delete(":group/members/:member")
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/api-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ await apiSdk.addMemberByInviteCode(groupId, memberId, inviteCode)

## Add member to groups using an API Key

\# **addMemberToGroupsByApiKey**(): _Promise\<Group[]>_
\# **addMemberToGroupsByApiKey**(): _Promise\<void>_

Adds a member to multiple groups using an API Key.

Expand Down
2 changes: 1 addition & 1 deletion libs/api-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ await apiSdk.addMemberByInviteCode(groupId, memberId, inviteCode)

## Add member to groups using an API Key

\# **addMemberToGroupsByApiKey**(): _Promise\<Group[]>_
\# **addMemberToGroupsByApiKey**(): _Promise\<void>_

Adds a member to multiple groups using an API Key.

Expand Down
6 changes: 2 additions & 4 deletions libs/api-sdk/src/apiSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,13 @@ export default class ApiSdk {
groupIds: string[],
memberId: string,
apiKey: string
): Promise<Group[]> {
const groups = await addMemberToGroupsByApiKey(
): Promise<void> {
await addMemberToGroupsByApiKey(
this._config,
groupIds,
memberId,
apiKey
)

return groups
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libs/api-sdk/src/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export function addMemberToGroupsByApiKey(
groupIds: string[],
memberId: string,
apiKey: string
): Promise<Group[]> {
): Promise<void> {
const newConfig: any = {
method: "post",
data: {
Expand Down
57 changes: 3 additions & 54 deletions libs/api-sdk/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,47 +852,7 @@ describe("Bandada API SDK", () => {

describe("#addMemberToGroups", () => {
it("Should add a member to multiple groups using an API Key", async () => {
const expectedGroups: Array<GroupCreationDetails> = [
{
name: "Group1",
description: "This is a new group",
treeDepth: 16,
fingerprintDuration: 3600
},
{
name: "Group2",
description: "This is a new group",
treeDepth: 32,
fingerprintDuration: 7200
}
]

requestMocked.mockImplementationOnce(() =>
Promise.resolve([
{
id: "10402173435763029700781503965100",
name: "Group1",
description: "This is a new group",
admin: "0xdf558148e66850ac48dbe2c8119b0eefa7d08bfd19c997c90a142eb97916b847",
treeDepth: 16,
fingerprintDuration: 3600,
createdAt: "2023-07-15T08:21:05.000Z",
members: ["1"],
credentials: null
},
{
id: "20402173435763029700781503965200",
name: "Group2",
description: "This is a new group",
admin: "0xdf558148e66850ac48dbe2c8119b0eefa7d08bfd19c997c90a142eb97916b847",
treeDepth: 32,
fingerprintDuration: 7200,
createdAt: "2023-07-15T08:21:05.000Z",
members: ["1"],
credentials: null
}
])
)
requestMocked.mockImplementationOnce(() => Promise.resolve())

const groupIds = [
"10402173435763029700781503965100",
Expand All @@ -902,24 +862,13 @@ describe("Bandada API SDK", () => {
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV)
const groups = await apiSdk.addMemberToGroupsByApiKey(
const res = await apiSdk.addMemberToGroupsByApiKey(
groupIds,
memberId,
apiKey
)

groups.forEach((group: Group, i: number) => {
expect(group.description).toBe(
expectedGroups[i].description
)
expect(group.name).toBe(expectedGroups[i].name)
expect(group.treeDepth).toBe(expectedGroups[i].treeDepth)
expect(group.fingerprintDuration).toBe(
expectedGroups[i].fingerprintDuration
)
expect(group.members).toHaveLength(1)
expect(group.credentials).toBeNull()
})
expect(res).toBeUndefined()
})
})

Expand Down

0 comments on commit 6a36eaf

Please sign in to comment.