From 3a4db75c1e1b8c2f1a1d2a351c62e23eddb2155b Mon Sep 17 00:00:00 2001 From: Zdravko Iliev <zdravko.iliev@vereign.com> Date: Mon, 4 Dec 2023 11:25:09 +0000 Subject: [PATCH] feat: add new endpoint for getting connection by out of band id --- agent-swagger.json | 30 ++++++++++++++++++++ apps/agent/README.md | 2 +- libs/askar/src/askar-rest/rest.controller.ts | 5 ++++ libs/askar/src/askar/agent.service.ts | 22 ++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/agent-swagger.json b/agent-swagger.json index 2e00ff9e..ddc983cb 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 63a0c611..4ac3348f 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 a1079c9a..f5c59309 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 9fde3b83..b74c6d42 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); -- GitLab