Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: webhook call to create proof presentation #385

Merged
merged 5 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions apps/api-gateway/src/verification/dto/webhook-proof.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiProperty } from "@nestjs/swagger";
import { ApiPropertyOptional } from "@nestjs/swagger";
import { IsOptional } from "class-validator";

interface IWebhookPresentationProof {
Expand All @@ -7,57 +7,57 @@ interface IWebhookPresentationProof {
connectionId
}

export class WebhookPresentationProof {
export class WebhookPresentationProofDto {

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
metadata: object;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
_tags: IWebhookPresentationProof;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
id: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
createdAt: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
protocolVersion: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
state: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
connectionId: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
threadId: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
presentationId: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
autoAcceptProof: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
updatedAt: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
isVerified: boolean;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
contextCorrelationId: string;
}
33 changes: 19 additions & 14 deletions apps/api-gateway/src/verification/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Roles } from '../authz/decorators/roles.decorator';
import { OrgRoles } from 'libs/org-roles/enums';
import { AuthGuard } from '@nestjs/passport';
import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { WebhookPresentationProof } from './dto/webhook-proof.dto';
import { WebhookPresentationProofDto } from './dto/webhook-proof.dto';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { ImageServiceService } from '@credebl/image-service';
import { User } from '../authz/decorators/user.decorator';
Expand Down Expand Up @@ -261,26 +261,31 @@ export class VerificationController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}

@Post('wh/:id/proofs')
/**
*
* @param orgId
* @returns Proof presentation details
*/
@Post('wh/:orgId/proofs')
@ApiOperation({
summary: `Webhook proof presentation`,
description: `Webhook proof presentation`
summary: `Receive webhook proof presentation`,
description: `Handle proof presentations for a specified organization via a webhook`
})
@ApiExcludeEndpoint()
@ApiResponse({ status: 201, description: 'Success', type: ApiResponseDto })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@ApiUnauthorizedResponse({ status: HttpStatus.UNAUTHORIZED, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden', type: ForbiddenErrorDto })
async webhookProofPresentation(
@Param('id') id: string,
@Body() proofPresentationPayload: WebhookPresentationProof,
@Param('orgId') orgId: string,
@Body() proofPresentationPayload: WebhookPresentationProofDto,
@Res() res: Response
): Promise<object> {
): Promise<Response> {
this.logger.debug(`proofPresentationPayload ::: ${JSON.stringify(proofPresentationPayload)}`);
const webhookProofPresentation = await this.verificationService.webhookProofPresentation(id, proofPresentationPayload);
const finalResponse: IResponseType = {
const webhookProofPresentation = await this.verificationService.webhookProofPresentation(orgId, proofPresentationPayload);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.verification.success.fetch,
data: webhookProofPresentation.response
message: ResponseMessages.verification.success.create,
data: webhookProofPresentation
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}
Expand Down
8 changes: 4 additions & 4 deletions apps/api-gateway/src/verification/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ClientProxy } from '@nestjs/microservices';
import { BaseService } from 'libs/service/base.service';
import { OutOfBandRequestProof, RequestProof } from './dto/request-proof.dto';
import { IUserRequest } from '@credebl/user-request/user-request.interface';
import { WebhookPresentationProof } from './dto/webhook-proof.dto';
import { WebhookPresentationProofDto } from './dto/webhook-proof.dto';
import { IProofRequestSearchCriteria } from './interfaces/verification.interface';
import { IProofPresentationList } from '@credebl/common/interfaces/verification.interface';

Expand Down Expand Up @@ -61,9 +61,9 @@ export class VerificationService extends BaseService {
return this.sendNats(this.verificationServiceProxy, 'verify-presentation', payload);
}

webhookProofPresentation(id: string, proofPresentationPayload: WebhookPresentationProof): Promise<{ response: object }> {
const payload = { id, proofPresentationPayload };
return this.sendNats(this.verificationServiceProxy, 'webhook-proof-presentation', payload);
webhookProofPresentation(orgId: string, proofPresentationPayload: WebhookPresentationProofDto): Promise<object> {
const payload = { orgId, proofPresentationPayload };
return this.sendNatsMessage(this.verificationServiceProxy, 'webhook-proof-presentation', payload);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions apps/verification/src/interfaces/verification.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ interface IWebhookPresentationProof {
connectionId
}

export interface IWebhookProofPresentationPayload {
proofPresentationDto: IWebhookProofPresentation;
id: string;
}
export interface IWebhookProofPresentation {
metadata: object;
_tags: IWebhookPresentationProof;
Expand All @@ -119,9 +115,9 @@ export interface IWebhookProofPresentation {
contextCorrelationId: string;
}

export interface ProofPresentationPayload {
export interface IProofPresentation {
proofPresentationPayload: IWebhookProofPresentation;
id: string;
orgId: string;
}

export interface IProofRequests {
Expand Down
11 changes: 6 additions & 5 deletions apps/verification/src/repositories/verification.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { PrismaService } from '@credebl/prisma-service';
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
// eslint-disable-next-line camelcase
import { org_agents, organisation, platform_config, presentations } from '@prisma/client';
import { IProofRequestSearchCriteria, ProofPresentationPayload } from '../interfaces/verification.interface';
import { IProofPresentation } from '../interfaces/verification.interface';
import { IProofRequestSearchCriteria } from '../interfaces/verification.interface';
import { IUserRequest } from '@credebl/user-request/user-request.interface';
import { IProofPresentationsListCount } from '@credebl/common/interfaces/verification.interface';
import { SortValue } from '@credebl/enum/enum';
Expand Down Expand Up @@ -103,16 +104,16 @@ export class VerificationRepository {
}
}

async storeProofPresentation(payload: ProofPresentationPayload): Promise<presentations> {
async storeProofPresentation(payload: IProofPresentation): Promise<presentations> {
try {
let organisationId: string;
const { proofPresentationPayload, id } = payload;
const { proofPresentationPayload, orgId } = payload;

if (proofPresentationPayload?.contextCorrelationId) {
const getOrganizationId = await this.getOrganizationByTenantId(proofPresentationPayload?.contextCorrelationId);
organisationId = getOrganizationId?.orgId;
} else {
organisationId = id;
organisationId = orgId;
}

const proofPresentationsDetails = await this.prisma.presentations.upsert({
Expand All @@ -138,7 +139,7 @@ export class VerificationRepository {
});
return proofPresentationsDetails;
} catch (error) {
this.logger.error(`Error in get saveIssuedCredentialDetails: ${error.message} `);
this.logger.error(`Error in get saveProofPresentationDetails: ${error.message} `);
throw error;
}
}
Expand Down
8 changes: 6 additions & 2 deletions apps/verification/src/verification.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from '@nestjs/common';
import { VerificationService } from './verification.service';
import { MessagePattern } from '@nestjs/microservices';
import { IProofRequests, IRequestProof, ProofFormData, ProofPresentationPayload } from './interfaces/verification.interface';
import { IProofPresentation, IProofRequests, IRequestProof, ProofFormData } from './interfaces/verification.interface';
import { IUserRequest } from '@credebl/user-request/user-request.interface';
import { presentations } from '@prisma/client';
import { IProofPresentationList } from '@credebl/common/interfaces/verification.interface';
Expand Down Expand Up @@ -51,8 +51,12 @@ export class VerificationController {
return this.verificationService.verifyPresentation(payload.id, payload.orgId);
}

/**
* @param orgId
* @returns proof presentation details
*/
@MessagePattern({ cmd: 'webhook-proof-presentation' })
async webhookProofPresentation(payload: ProofPresentationPayload): Promise<presentations> {
async webhookProofPresentation(payload: IProofPresentation): Promise<presentations> {
return this.verificationService.webhookProofPresentation(payload);
}

Expand Down
5 changes: 2 additions & 3 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { BadRequestException, HttpException, Inject, Injectable, InternalServerErrorException, Logger, NotFoundException } from '@nestjs/common';
import { ClientProxy, RpcException } from '@nestjs/microservices';
import { map } from 'rxjs/operators';
import { IGetAllProofPresentations, IGetProofPresentationById, IProofRequestPayload, IProofRequestSearchCriteria, IRequestProof, ISendProofRequestPayload, IVerifyPresentation, ProofFormDataPayload, ProofPresentationPayload } from './interfaces/verification.interface';
import { IGetAllProofPresentations, IProofRequestSearchCriteria, IGetProofPresentationById, IProofPresentation, IProofRequestPayload, IRequestProof, ISendProofRequestPayload, IVerifyPresentation, ProofFormDataPayload } from './interfaces/verification.interface';
import { VerificationRepository } from './repositories/verification.repository';
import { CommonConstants } from '@credebl/common/common.constant';
import { org_agents, organisation, presentations } from '@prisma/client';
Expand Down Expand Up @@ -365,9 +365,8 @@ export class VerificationService {
}
}

async webhookProofPresentation(proofPresentationPayload: ProofPresentationPayload): Promise<presentations> {
async webhookProofPresentation(proofPresentationPayload: IProofPresentation): Promise<presentations> {
try {

const proofPresentation = await this.verificationRepository.storeProofPresentation(proofPresentationPayload);
return proofPresentation;

Expand Down
1 change: 1 addition & 0 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const ResponseMessages = {
verification: {
success: {
fetch: 'Proof presentations details fetched successfully.',
create: 'Presentation of proof details created successfully.',
proofFormData: 'Proof presentation form data received successfully.',
send: 'Proof request send successfully.',
verified: 'Proof presentation verified successfully.'
Expand Down