Skip to content

Commit

Permalink
fix: connection query
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Apr 4, 2024
1 parent 7a8dd9a commit f3dee78
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/controllers/connections/ConnectionController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectionRepository, DidExchangeState, RecordNotFoundError } from '@credo-ts/core'
import { DidExchangeState, RecordNotFoundError } from '@credo-ts/core'
import {
Controller,
Delete,
Expand Down Expand Up @@ -34,40 +34,42 @@ export class ConnectionController {
*/
@Get('/')
@ApiQuery({ name: 'outOfBandId', required: false, type: String })
@ApiQuery({ name: 'alias', required: false, type: String })
@ApiQuery({ name: 'state', required: false, type: String })
@ApiQuery({ name: 'myDid', required: false, type: String })
@ApiQuery({ name: 'did', required: false, type: String })
@ApiQuery({ name: 'theirDid', required: false, type: String })
@ApiQuery({ name: 'theirLabel', required: false, type: String })
@ApiQuery({ name: 'threadId', required: false, type: String })
public async getAllConnections(
@Query('outOfBandId') outOfBandId?: string,
@Query('alias') alias?: string,
@Query('state') state?: DidExchangeState,
@Query('myDid') myDid?: string,
@Query('did') did?: string,
@Query('theirDid') theirDid?: string,
@Query('theirLabel') theirLabel?: string,
@Query('threadId') threadId?: string,
) {
const agent = await this.agentService.getAgent()

let connections
const connections = await agent.connections.findAllByQuery({
did,
theirDid,
threadId,
state,
outOfBandId,
})

if (outOfBandId) {
connections = await agent.connections.findAllByOutOfBandId(outOfBandId)
} else {
const connectionRepository = agent.dependencyManager.resolve(ConnectionRepository)

const connections = await connectionRepository.findByQuery(agent.context, {
alias,
myDid,
theirDid,
theirLabel,
state,
})

return connections.map(c => c.toJSON())
}

return connections.map(c => c.toJSON())
return connections.map(record => ({
id: record.id,
createdAt: record.createdAt,
updatedAt: record.updatedAt,
did: record.did,
theirDid: record.theirDid,
theirLabel: record.theirLabel,
state: record.state,
role: record.role,
alias: record.alias,
threadId: record.threadId,
imageUrl: record.imageUrl,
outOfBandId: record.outOfBandId,
invitationDid: record.invitationDid,
}))
}

/**
Expand Down

0 comments on commit f3dee78

Please sign in to comment.