Skip to content

Commit

Permalink
fix: connection list from agent (#578)
Browse files Browse the repository at this point in the history
* feat: added connection list from agent

Signed-off-by: tipusinghaw <[email protected]>

* feat: agent connection list API

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
tipusinghaw authored and KulkarniShashank committed Sep 11, 2024
1 parent d1f09a5 commit df101fe
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 148 deletions.
14 changes: 3 additions & 11 deletions apps/agent-service/src/agent-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { MessagePattern } from '@nestjs/microservices';
import { AgentServiceService } from './agent-service.service';
import { IAgentStatus, IConnectionDetails, IUserRequestInterface, ISendProofRequestPayload, IAgentSpinUpSatus, IGetCredDefAgentRedirection, IGetSchemaAgentRedirection, IAgentSpinupDto, IIssuanceCreateOffer, ITenantCredDef, ITenantDto, ITenantSchema, IOutOfBandCredentialOffer, IProofPresentation, IAgentProofRequest, IPresentation } from './interface/agent-service.interface';
import { user } from '@prisma/client';
import { ICreateConnectionUrl } from '@credebl/common/interfaces/connection.interface';
import { IConnectionDetailsById } from 'apps/api-gateway/src/interfaces/IConnectionSearch.interface';
import { IProofPresentationDetails } from '@credebl/common/interfaces/verification.interface';
import { InvitationMessage } from '@credebl/common/interfaces/agent-service.interface';

@Controller()
export class AgentServiceController {
Expand Down Expand Up @@ -53,16 +53,8 @@ export class AgentServiceController {

//DONE
@MessagePattern({ cmd: 'agent-create-connection-legacy-invitation' })
async createLegacyConnectionInvitation(payload: {
connectionPayload: IConnectionDetails;
url: string;
apiKey: string;
}): Promise<object> {
return this.agentServiceService.createLegacyConnectionInvitation(
payload.connectionPayload,
payload.url,
payload.apiKey
);
async createLegacyConnectionInvitation(payload: { connectionPayload: IConnectionDetails, url: string, apiKey: string }): Promise<InvitationMessage> {
return this.agentServiceService.createLegacyConnectionInvitation(payload.connectionPayload, payload.url, payload.apiKey);
}

//DONE
Expand Down
3 changes: 2 additions & 1 deletion apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { IProofPresentationDetails } from '@credebl/common/interfaces/verification.interface';
import { ICreateConnectionUrl } from '@credebl/common/interfaces/connection.interface';
import { IConnectionDetailsById } from 'apps/api-gateway/src/interfaces/IConnectionSearch.interface';
import { InvitationMessage } from '@credebl/common/interfaces/agent-service.interface';

@Injectable()
@WebSocketGateway()
Expand Down Expand Up @@ -945,7 +946,7 @@ export class AgentServiceService {
}
}

async createLegacyConnectionInvitation(connectionPayload: IConnectionDetails, url: string, apiKey: string): Promise<ICreateConnectionUrl> {
async createLegacyConnectionInvitation(connectionPayload: IConnectionDetails, url: string, apiKey: string): Promise<InvitationMessage> {
try {


Expand Down
38 changes: 35 additions & 3 deletions apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler
import { OrgRoles } from 'libs/org-roles/enums';
import { Roles } from '../authz/decorators/roles.decorator';
import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { GetAllConnectionsDto } from './dtos/get-all-connections.dto';
import { IConnectionSearchinterface } from '../interfaces/ISchemaSearch.interface';
import { GetAllAgentConnectionsDto, GetAllConnectionsDto } from './dtos/get-all-connections.dto';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
import { IConnectionSearchCriteria } from '../interfaces/IConnectionSearch.interface';
import { SortFields } from 'apps/connection/src/enum/connection.enum';
Expand Down Expand Up @@ -108,7 +107,40 @@ export class ConnectionController {
return res.status(HttpStatus.OK).json(finalResponse);
}


/**
* Description: Get all connections from agent
* @param user
* @param orgId
*
*/
@Get('/orgs/:orgId/agent/connections')
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER)
@ApiOperation({
summary: `Fetch all connections from agent by orgId`,
description: `Fetch all connections from agent by orgId`
})
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
async getConnectionListFromAgent(
@Query() getAllConnectionsDto: GetAllAgentConnectionsDto,
@Param('orgId') orgId: string,
@Res() res: Response
): Promise<Response> {

const connectionDetails = await this.connectionService.getConnectionListFromAgent(
getAllConnectionsDto,
orgId
);

const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.connection.success.fetch,
data: connectionDetails
};
return res.status(HttpStatus.OK).json(finalResponse);
}


@Get('orgs/:orgId/question-answer/question')
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER, OrgRoles.HOLDER, OrgRoles.SUPER_ADMIN, OrgRoles.PLATFORM_ADMIN)
Expand Down
10 changes: 9 additions & 1 deletion apps/api-gateway/src/connection/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BaseService } from 'libs/service/base.service';
import { ConnectionDto, CreateConnectionDto, ReceiveInvitationDto, ReceiveInvitationUrlDto } from './dtos/connection.dto';
import { IReceiveInvitationRes, IUserRequestInterface } from './interfaces';
import { IConnectionList, ICreateConnectionUrl } from '@credebl/common/interfaces/connection.interface';
import { IConnectionDetailsById, IConnectionSearchCriteria } from '../interfaces/IConnectionSearch.interface';
import { AgentConnectionSearchCriteria, IConnectionDetailsById, IConnectionSearchCriteria } from '../interfaces/IConnectionSearch.interface';
import { QuestionDto } from './dtos/question-answer.dto';

@Injectable()
Expand Down Expand Up @@ -77,6 +77,14 @@ export class ConnectionService extends BaseService {
return this.sendNatsMessage(this.connectionServiceProxy, 'get-all-connections', payload);
}

getConnectionListFromAgent(
connectionSearchCriteria: AgentConnectionSearchCriteria,
orgId: string
): Promise<IConnectionList> {
const payload = { connectionSearchCriteria, orgId };
return this.sendNatsMessage(this.connectionServiceProxy, 'get-all-agent-connection-list', payload);
}

getConnectionsById(
user: IUserRequest,
connectionId: string,
Expand Down
94 changes: 57 additions & 37 deletions apps/api-gateway/src/connection/dtos/get-all-connections.dto.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
import { ApiProperty } from "@nestjs/swagger";
import { Transform, Type } from "class-transformer";
import { IsEnum, IsOptional } from "class-validator";
import { SortValue } from "../../enum";
import { trim } from "@credebl/common/cast.helper";
import { SortFields } from "apps/connection/src/enum/connection.enum";
import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsEnum, IsOptional } from 'class-validator';
import { SortValue } from '../../enum';
import { trim } from '@credebl/common/cast.helper';
import { SortFields } from 'apps/connection/src/enum/connection.enum';

export class GetAllConnectionsDto {

@ApiProperty({ required: false, example: '1' })
@IsOptional()
pageNumber: number = 1;

@ApiProperty({ required: false, example: '10' })
@IsOptional()
pageSize: number = 10;

@ApiProperty({ required: false })
@IsOptional()
@Transform(({ value }) => trim(value))
@Type(() => String)
searchByText: string = '';

@ApiProperty({
required: false
})
@Transform(({ value }) => trim(value))
@IsOptional()
@IsEnum(SortFields)
sortField: string = SortFields.CREATED_DATE_TIME;

@ApiProperty({
enum: [SortValue.DESC, SortValue.ASC],
required: false
})
@Transform(({ value }) => trim(value))
@IsOptional()
@IsEnum(SortValue)
sortBy: string = SortValue.DESC;
@ApiProperty({ required: false, example: '1' })
@IsOptional()
pageNumber: number = 1;

@ApiProperty({ required: false, example: '10' })
@IsOptional()
pageSize: number = 10;

@ApiProperty({ required: false })
@IsOptional()
@Transform(({ value }) => trim(value))
@Type(() => String)
searchByText: string = '';

@ApiProperty({
required: false
})
@Transform(({ value }) => trim(value))
@IsOptional()
@IsEnum(SortFields)
sortField: string = SortFields.CREATED_DATE_TIME;

@ApiProperty({
enum: [SortValue.DESC, SortValue.ASC],
required: false
})
@Transform(({ value }) => trim(value))
@IsOptional()
@IsEnum(SortValue)
sortBy: string = SortValue.DESC;
}

export class GetAllAgentConnectionsDto {
@ApiProperty({ required: false, example: 'e315f30d-9beb-4068-aea4-abb5fe5eecb1' })
@IsOptional()
outOfBandId: string = '';

@ApiProperty({ required: false, example: 'Test' })
@IsOptional()
alias: string = '';

@ApiProperty({ required: false, example: 'did:example:e315f30d-9beb-4068-aea4-abb5fe5eecb1' })
@IsOptional()
myDid: string = '';

@ApiProperty({ required: false, example: 'did:example:e315f30d-9beb-4068-aea4-abb5fe5eecb1' })
@IsOptional()
theirDid: string = '';

@ApiProperty({ required: false, example: 'Bob' })
@IsOptional()
theirLabel: string = '';
}
47 changes: 28 additions & 19 deletions apps/api-gateway/src/interfaces/IConnectionSearch.interface.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import { IUserRequestInterface } from './IUserRequestInterface';

export interface IConnectionSearchCriteria {
pageNumber: number;
pageSize: number;
sortField: string;
sortBy: string;
searchByText: string;
user?: IUserRequestInterface
pageNumber: number;
pageSize: number;
sortField: string;
sortBy: string;
searchByText: string;
user?: IUserRequestInterface;
}

export interface IConnectionDetailsById {
id: string;
createdAt: string;
did: string;
theirDid: string;
theirLabel: string;
state: string;
role: string;
autoAcceptConnection: boolean;
threadId: string;
protocol: string;
outOfBandId: string;
updatedAt: string;
}
id: string;
createdAt: string;
did: string;
theirDid: string;
theirLabel: string;
state: string;
role: string;
autoAcceptConnection: boolean;
threadId: string;
protocol: string;
outOfBandId: string;
updatedAt: string;
}

export interface AgentConnectionSearchCriteria {
outOfBandId?: string;
alias?: string;
state?: string;
myDid?: string;
theirDid?: string;
theirLabel?: string;
}
7 changes: 7 additions & 0 deletions apps/connection/src/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Controller } from '@nestjs/common'; // Import the common service in the
import { ConnectionService } from './connection.service'; // Import the common service in connection module
import { MessagePattern } from '@nestjs/microservices'; // Import the nestjs microservices package
import {
GetAllConnections,
IConnection,
ICreateConnection,
IFetchConnectionById,
Expand Down Expand Up @@ -54,6 +55,12 @@ export class ConnectionController {
return this.connectionService.getConnections(user, orgId, connectionSearchCriteria);
}

@MessagePattern({ cmd: 'get-all-agent-connection-list' })
async getConnectionListFromAgent(payload: GetAllConnections): Promise<string> {
const {orgId, connectionSearchCriteria } = payload;
return this.connectionService.getAllConnectionListFromAgent(orgId, connectionSearchCriteria);
}

/**
*
* @param connectionId
Expand Down
Loading

0 comments on commit df101fe

Please sign in to comment.