Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-sdk): fix get groups function #562

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading