Skip to content

Commit

Permalink
Merge pull request #562 from bandada-infra/fix/get-groups-api-sdk
Browse files Browse the repository at this point in the history
fix(api-sdk): fix get groups function
  • Loading branch information
vplasencia authored Sep 25, 2024
2 parents 89b67ae + 0f83944 commit 805969e
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/app/groups/docSchemas/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export class Group {
@ApiProperty({ isArray: true })
members: string
@ApiProperty()
credentials: object
credentials: string
}
6 changes: 5 additions & 1 deletion apps/api/src/app/groups/dto/create-group.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class CreateGroupDto {

@IsJSON()
@IsOptional()
@ApiProperty()
@ApiProperty({
default:
'{"id":"BLOCKCHAIN_BALANCE","criteria":{"minBalance":"10","network":"Sepolia"}}',
type: String
})
readonly credentials?: any
}
85 changes: 68 additions & 17 deletions libs/api-sdk/src/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ const url = "/groups"
* @returns List of groups.
*/
export async function getGroups(config: object): Promise<Group[]> {
const groups = await request(url, config)
let groups = await request(url, config)

groups.map((group: any) => ({
...group,
credentials: JSON.parse(group.credentials)
}))
groups = groups.map((group: any) => {
let credentials

try {
credentials = JSON.parse(group.credentials)
} catch (error) {
credentials = null
}

return {
...group,
credentials
}
})

return groups
}
Expand All @@ -34,12 +44,22 @@ export async function getGroupsByAdminId(
): Promise<Group[]> {
const requestUrl = `${url}?adminId=${adminId}`

const groups = await request(requestUrl, config)
let groups = await request(requestUrl, config)

groups = groups.map((group: any) => {
let credentials

groups.map((group: any) => ({
...group,
credentials: JSON.parse(group.credentials)
}))
try {
credentials = JSON.parse(group.credentials)
} catch (error) {
credentials = null
}

return {
...group,
credentials
}
})

return groups
}
Expand All @@ -55,12 +75,22 @@ export async function getGroupsByMemberId(
): Promise<Group[]> {
const requestUrl = `${url}?memberId=${memberId}`

const groups = await request(requestUrl, config)
let groups = await request(requestUrl, config)

groups = groups.map((group: any) => {
let credentials

groups.map((group: any) => ({
...group,
credentials: JSON.parse(group.credentials)
}))
try {
credentials = JSON.parse(group.credentials)
} catch (error) {
credentials = null
}

return {
...group,
credentials
}
})

return groups
}
Expand All @@ -76,9 +106,22 @@ export async function createGroups(
groupsCreationDetails: Array<GroupCreationDetails>,
apiKey: string
): Promise<Array<Group>> {
const groupsCreationDetailsRequest = groupsCreationDetails.map((group) => {
if (group.credentials) {
return {
...group,
credentials: JSON.stringify(group.credentials)
}
}

return {
...group
}
})

const newConfig: any = {
method: "post",
data: groupsCreationDetails,
data: groupsCreationDetailsRequest,
...config
}

Expand Down Expand Up @@ -204,7 +247,15 @@ export async function getGroup(

const group = await request(requestUrl, config)

group.credentials = JSON.parse(group.credentials)
let credentials

try {
credentials = JSON.parse(group.credentials)
} catch (error) {
credentials = null
}

group.credentials = credentials

return group
}
Expand Down
Loading

0 comments on commit 805969e

Please sign in to comment.