diff --git a/agent-swagger.json b/agent-swagger.json index 2e00ff9eb78054378b1c93846577049557718103..ddc983cbd6848d36128a6d3a29524818d7ccf673 100644 --- a/agent-swagger.json +++ b/agent-swagger.json @@ -123,6 +123,36 @@ } } }, + "/api/v1/connections/oob/{id}": { + "get": { + "operationId": "RestController_getConnectionByOobId", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ConnectionRecordDto" + } + } + } + } + } + } + } + }, "/api/v1/schemas": { "post": { "operationId": "RestController_createSchema", diff --git a/apps/agent/README.md b/apps/agent/README.md index 63a0c6113ee88579512ff090302b25584e202825..4ac3348f0ac105fab17515d54b5b7442a06ea0b9 100644 --- a/apps/agent/README.md +++ b/apps/agent/README.md @@ -1,4 +1,4 @@ -# OCM ENGINE - AGENT +# OCM ENGINE - AGENT Agent service is a wrapper around @ocm-engine/askar library. diff --git a/libs/askar/src/askar-rest/rest.controller.ts b/libs/askar/src/askar-rest/rest.controller.ts index a1079c9a0d853dc7ffbfed6a188946040a94641b..f5c5930942c10815a779d7b4666b4a878cf37935 100644 --- a/libs/askar/src/askar-rest/rest.controller.ts +++ b/libs/askar/src/askar-rest/rest.controller.ts @@ -66,6 +66,11 @@ export class RestController { return this.agentService.deleteConnectionById(id); } + @Get("/connections/oob/:id") + async getConnectionByOobId(@Param("id") id: string) { + return this.agentService.getConnectionByOobId(id); + } + @Post("/schemas") async createSchema(@Body() schemaDto: CreateSchemaRequestDto) { return this.agentService.createSchema(schemaDto); diff --git a/libs/askar/src/askar/agent.service.ts b/libs/askar/src/askar/agent.service.ts index 9fde3b83f1868134ee7408ccd5527e0fa2b7e9af..b74c6d42e67bbe5b9b03f83962c9cb19a6a8ecf5 100644 --- a/libs/askar/src/askar/agent.service.ts +++ b/libs/askar/src/askar/agent.service.ts @@ -111,6 +111,28 @@ export class AgentService { return connectionArray; } + getConnectionByOobId = async (oobId: string) => { + const connectionRecords = + await this.askar.agent.connections.findAllByOutOfBandId(oobId); + + const connectionArray = connectionRecords.map((singleConnectionRes) => { + const connectionResponse = new ConnectionRecordDto(); + connectionResponse.id = singleConnectionRes.id; + connectionResponse.state = singleConnectionRes.state; + connectionResponse.connectionName = singleConnectionRes.theirLabel; + connectionResponse.alias = singleConnectionRes.alias; + connectionResponse.did = singleConnectionRes.did; + connectionResponse.invitationDid = singleConnectionRes.invitationDid; + connectionResponse.outOfBandId = singleConnectionRes.outOfBandId; + connectionResponse.createdAt = singleConnectionRes.createdAt; + connectionResponse.imageUrl = singleConnectionRes.imageUrl; + + return connectionResponse; + }); + + return connectionArray; + }; + getConnectionById = async (id: string): Promise<ConnectionRecordDto> => { const agentResponse = await this.askar.agent.connections.findById(id);