Skip to content

Commit 5aa97a2

Browse files
authored
fix(data-store): return unique credentials for dataStoreORMGetVerifiableCredentialsByClaims (#1299)
fixes #1285 Co-authored-by: Mirko Mollik <[email protected]>
1 parent ea2d99a commit 5aa97a2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/data-store/src/__tests__/data-store-orm.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe('@veramo/data-store queries', () => {
261261

262262
test('works with relations', async () => {
263263
const credentials = await makeAgent().dataStoreORMGetVerifiableCredentialsByClaims({})
264-
expect(credentials.length).toBe(3)
264+
expect(credentials.length).toBe(1)
265265
expect(credentials[0].verifiableCredential.id).toBe('vc1')
266266
const count = await makeAgent().dataStoreORMGetVerifiableCredentialsByClaimsCount({})
267267
expect(count).toBe(3)

packages/data-store/src/data-store-orm.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,17 @@ export class DataStoreORM implements IAgentPlugin {
202202
context: AuthorizedDIDContext,
203203
): Promise<Array<UniqueVerifiableCredential>> {
204204
const claims = await (await this.claimsQuery(args, context)).getMany()
205-
return claims.map((claim) => ({
206-
hash: claim.credential.hash,
207-
verifiableCredential: claim.credential.raw,
208-
}))
205+
return claims
206+
.map((claim) => ({
207+
hash: claim.credential.hash,
208+
verifiableCredential: claim.credential.raw,
209+
}))
210+
.reduce((acc: UniqueVerifiableCredential[], current: UniqueVerifiableCredential) => {
211+
if (!acc.some((item) => item.hash === current.hash)) {
212+
acc.push(current)
213+
}
214+
return acc
215+
}, [])
209216
}
210217

211218
async dataStoreORMGetVerifiableCredentialsByClaimsCount(

0 commit comments

Comments
 (0)