Skip to content

Commit

Permalink
fix(data-store): return unique credentials for `dataStoreORMGetVerifi…
Browse files Browse the repository at this point in the history
…ableCredentialsByClaims` (#1299)

fixes #1285

Co-authored-by: Mirko Mollik <mirko.mollik@fit.fraunhofer.de>
  • Loading branch information
cre8 and cre8 authored Dec 8, 2023
1 parent ea2d99a commit 5aa97a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/data-store/src/__tests__/data-store-orm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('@veramo/data-store queries', () => {

test('works with relations', async () => {
const credentials = await makeAgent().dataStoreORMGetVerifiableCredentialsByClaims({})
expect(credentials.length).toBe(3)
expect(credentials.length).toBe(1)
expect(credentials[0].verifiableCredential.id).toBe('vc1')
const count = await makeAgent().dataStoreORMGetVerifiableCredentialsByClaimsCount({})
expect(count).toBe(3)
Expand Down
15 changes: 11 additions & 4 deletions packages/data-store/src/data-store-orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,17 @@ export class DataStoreORM implements IAgentPlugin {
context: AuthorizedDIDContext,
): Promise<Array<UniqueVerifiableCredential>> {
const claims = await (await this.claimsQuery(args, context)).getMany()
return claims.map((claim) => ({
hash: claim.credential.hash,
verifiableCredential: claim.credential.raw,
}))
return claims
.map((claim) => ({
hash: claim.credential.hash,
verifiableCredential: claim.credential.raw,
}))
.reduce((acc: UniqueVerifiableCredential[], current: UniqueVerifiableCredential) => {
if (!acc.some((item) => item.hash === current.hash)) {
acc.push(current)
}
return acc
}, [])
}

async dataStoreORMGetVerifiableCredentialsByClaimsCount(
Expand Down

0 comments on commit 5aa97a2

Please sign in to comment.