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: Dev to main #304

Merged
merged 10 commits into from
Nov 25, 2023
4 changes: 2 additions & 2 deletions apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ export class ConnectionController {
@ApiResponse({ status: 200, description: 'Success', type: AuthTokenResponse })
async getConnectionWebhook(
@Body() connectionDto: ConnectionDto,
@Param('id') id: number,
@Param('id') id: string,
@Res() res: Response
): Promise<object> {
this.logger.debug(`connectionDto ::: ${JSON.stringify(connectionDto)}`);
this.logger.debug(`connectionDto ::: ${JSON.stringify(connectionDto)} ${id}`);
const connectionData = await this.connectionService.getConnectionWebhook(connectionDto, id);
const finalResponse: IResponseType = {
statusCode: HttpStatus.CREATED,
Expand Down
2 changes: 1 addition & 1 deletion apps/api-gateway/src/connection/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ConnectionService extends BaseService {
}
}

getConnectionWebhook(connectionDto: ConnectionDto, id: number): Promise<{
getConnectionWebhook(connectionDto: ConnectionDto, id: string): Promise<{
response: object;
}> {
const payload = { connectionId: connectionDto.id, state: connectionDto.state, orgDid: connectionDto.theirDid, theirLabel: connectionDto.theirLabel, autoAcceptConnection: connectionDto.autoAcceptConnection, outOfBandId: connectionDto.outOfBandId, createDateTime: connectionDto.createdAt, lastChangedDateTime: connectionDto.updatedAt, orgId: id };
Expand Down
2 changes: 1 addition & 1 deletion apps/api-gateway/src/issuance/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class IssuanceService extends BaseService {
getIssueCredentialWebhook(issueCredentialDto: IssuanceDto, id: string): Promise<{
response: object;
}> {
const payload = { createDateTime: issueCredentialDto.createdAt, connectionId: issueCredentialDto.connectionId, threadId: issueCredentialDto.threadId, protocolVersion: issueCredentialDto.protocolVersion, credentialAttributes: issueCredentialDto.credentialAttributes, orgId: id };
const payload = { issueCredentialDto, id };
return this.sendNats(this.issuanceProxy, 'webhook-get-issue-credential', payload);
}

Expand Down
24 changes: 23 additions & 1 deletion apps/api-gateway/src/platform/platform.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, HttpStatus, Logger, Query, Res, UseFilters, UseGuards } from '@nestjs/common';
import { Controller, Get, HttpStatus, Logger, Param, Query, Res, UseFilters, UseGuards } from '@nestjs/common';
import { PlatformService } from './platform.service';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
Expand Down Expand Up @@ -71,5 +71,27 @@ export class PlatformController {
};
return res.status(HttpStatus.OK).json(finalResponse);
}

@Get('/network/url/:indyNamespace')
@ApiTags('ledgers')
@ApiOperation({
summary: 'Get network url from platform.',
description: 'Get network url from platform.'
})
@UseGuards(AuthGuard('jwt'))
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
async getNetwrkUrl(
@Param('indyNamespace') indyNamespace: string,
@Res() res: Response
): Promise<object> {
const networksResponse = await this.platformService.getNetworkUrl(indyNamespace);

const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.ledger.success.fetch,
data: networksResponse.response
};
return res.status(HttpStatus.OK).json(finalResponse);
}
}

9 changes: 9 additions & 0 deletions apps/api-gateway/src/platform/platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ export class PlatformService extends BaseService {
const payload = {};
return this.sendNats(this.platformServiceProxy, 'get-all-ledgers', payload);
}

async getNetworkUrl(indyNamespace: string): Promise<{
response: object;
}> {
const payload = {
indyNamespace
};
return this.sendNats(this.platformServiceProxy, 'get-network-url', payload);
}
}
11 changes: 2 additions & 9 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,15 @@ export class ConnectionRepository {
// eslint-disable-next-line camelcase
async saveConnectionWebhook(createDateTime: string, lastChangedDateTime: string, connectionId: string, state: string, orgDid: string, theirLabel: string, autoAcceptConnection: boolean, outOfBandId: string, orgId: string): Promise<connections> {
try {

const agentDetails = await this.prisma.connections.upsert({
where: {
connectionId
},
update: {
lastChangedDateTime,
lastChangedBy: orgId,
state,
orgDid,
theirLabel,
autoAcceptConnection,
outOfBandId
state
},
create: {
createDateTime,
Expand All @@ -116,10 +113,6 @@ export class ConnectionRepository {
lastChangedBy: orgId,
connectionId,
state,
orgDid,
theirLabel,
autoAcceptConnection,
outOfBandId,
orgId
}
});
Expand Down
13 changes: 10 additions & 3 deletions apps/issuance/interfaces/issuance.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export interface IIssuanceWebhookInterface {
protocolVersion: string;
credentialAttributes: ICredentialAttributesInterface[];
orgId: string;
id: string;
state: string;
}

export interface IssueCredentialWebhookPayload {
issueCredentialDto: IIssuanceWebhookInterface;
id: string;
}

export interface ICredentialAttributesInterface {
Expand Down Expand Up @@ -87,10 +94,10 @@ export interface FileUpload {
name?: string;
upload_type?: string;
status?: string;
orgId?: string;
orgId?: string;
createDateTime?: Date;
lastChangedDateTime?: Date;
}
}

export interface FileUploadData {
fileUpload: string;
Expand All @@ -104,7 +111,7 @@ export interface FileUploadData {
}

export interface ClientDetails {

clientId: string;

userId?: string;
Expand Down
9 changes: 4 additions & 5 deletions apps/issuance/src/issuance.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Logger } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { ClientDetails, IIssuance, IIssuanceWebhookInterface, IIssueCredentials, IIssueCredentialsDefinitions, ImportFileDetails, OutOfBandCredentialOffer, PreviewRequest } from '../interfaces/issuance.interfaces';
import { ClientDetails, IIssuance, IIssueCredentials, IIssueCredentialsDefinitions, ImportFileDetails, IssueCredentialWebhookPayload, OutOfBandCredentialOffer, PreviewRequest } from '../interfaces/issuance.interfaces';
import { IssuanceService } from './issuance.service';

@Controller()
Expand Down Expand Up @@ -36,10 +36,9 @@ export class IssuanceController {


@MessagePattern({ cmd: 'webhook-get-issue-credential' })
async getIssueCredentialWebhook(payload: IIssuanceWebhookInterface): Promise<object> {
const { createDateTime, connectionId, threadId, protocolVersion, credentialAttributes, orgId } = payload;

return this.issuanceService.getIssueCredentialWebhook(createDateTime, connectionId, threadId, protocolVersion, credentialAttributes, orgId);
async getIssueCredentialWebhook(payload: IssueCredentialWebhookPayload): Promise<object> {
const { issueCredentialDto, id } = payload;
return this.issuanceService.getIssueCredentialWebhook(issueCredentialDto, id);
}

@MessagePattern({ cmd: 'out-of-band-credential-offer' })
Expand Down
21 changes: 10 additions & 11 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PrismaService } from '@credebl/prisma-service';
// eslint-disable-next-line camelcase
import { agent_invitations, credentials, file_data, file_upload, org_agents, organisation, platform_config, shortening_url } from '@prisma/client';
import { ResponseMessages } from '@credebl/common/response-messages';
import { FileUploadData, PreviewRequest, SchemaDetails } from '../interfaces/issuance.interfaces';
import { FileUploadData, IIssuanceWebhookInterface, PreviewRequest, SchemaDetails } from '../interfaces/issuance.interfaces';
import { FileUploadStatus } from 'apps/api-gateway/src/enum';
@Injectable()
export class IssuanceRepository {
Expand Down Expand Up @@ -48,9 +48,10 @@ export class IssuanceRepository {
* @returns Get saved credential details
*/
// eslint-disable-next-line camelcase
async saveIssuedCredentialDetails(createDateTime: string, connectionId: string, threadId: string, protocolVersion: string, credentialAttributes: object[], orgId: string): Promise<credentials> {
async saveIssuedCredentialDetails(payload: IIssuanceWebhookInterface, orgId: string): Promise<credentials> {
try {

const { connectionId, createDateTime, id, threadId, state } = payload;
const credentialDetails = await this.prisma.credentials.upsert({
where: {
threadId
Expand All @@ -59,19 +60,17 @@ export class IssuanceRepository {
lastChangedBy: orgId,
createDateTime,
threadId,
protocolVersion,
credentialAttributes,
orgId: String(orgId)
state
},
create: {
createDateTime,
lastChangedBy: orgId,
createdBy: orgId,
connectionId,
state,
threadId,
protocolVersion,
credentialAttributes,
orgId: String(orgId)
credentialExchangeId: id,
orgId
}
});
return credentialDetails;
Expand Down Expand Up @@ -284,7 +283,7 @@ export class IssuanceRepository {
skip: (getAllfileDetails?.pageNumber - 1) * getAllfileDetails?.pageSize,
orderBy: {
createDateTime: 'desc'
}
}
});

const fileListWithDetails = await Promise.all(
Expand Down Expand Up @@ -343,7 +342,7 @@ export class IssuanceRepository {
skip: (getAllfileDetails?.pageNumber - 1) * getAllfileDetails?.pageSize,
orderBy: {
createDateTime: 'desc'
}
}
});
const fileCount = await this.prisma.file_data.count({
where: {
Expand Down Expand Up @@ -386,7 +385,7 @@ export class IssuanceRepository {
return this.prisma.file_data.update({
where: { id: jobId },
data: {
credential_data: null
credential_data: null
}
});
}
Expand Down
10 changes: 5 additions & 5 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CommonConstants } from '@credebl/common/common.constant';
import { ResponseMessages } from '@credebl/common/response-messages';
import { ClientProxy, RpcException } from '@nestjs/microservices';
import { map } from 'rxjs';
import { ClientDetails, FileUploadData, ICredentialAttributesInterface, ImportFileDetails, OutOfBandCredentialOfferPayload, PreviewRequest, SchemaDetails } from '../interfaces/issuance.interfaces';
import { ClientDetails, FileUploadData, IIssuanceWebhookInterface, ImportFileDetails, OutOfBandCredentialOfferPayload, PreviewRequest, SchemaDetails } from '../interfaces/issuance.interfaces';
import { OrgAgentType } from '@credebl/enum/enum';
import { platform_config } from '@prisma/client';
import * as QRCode from 'qrcode';
Expand Down Expand Up @@ -262,9 +262,9 @@ export class IssuanceService {
}
}

async getIssueCredentialWebhook(createDateTime: string, connectionId: string, threadId: string, protocolVersion: string, credentialAttributes: ICredentialAttributesInterface[], orgId: string): Promise<object> {
async getIssueCredentialWebhook(payload: IIssuanceWebhookInterface, id: string): Promise<object> {
try {
const agentDetails = await this.issuanceRepository.saveIssuedCredentialDetails(createDateTime, connectionId, threadId, protocolVersion, credentialAttributes, orgId);
const agentDetails = await this.issuanceRepository.saveIssuedCredentialDetails(payload, id);
return agentDetails;
} catch (error) {
this.logger.error(`[getIssueCredentialsbyCredentialRecordId] - error in get credentials : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -624,15 +624,15 @@ export class IssuanceService {
}

await this.validateFileHeaders(fileHeader, attributeNameArray);
await this.validateFileData(fileData);
await this.validateFileData(fileData);

const resData = {
schemaLedgerId: credDefResponse.schemaLedgerId,
credentialDefinitionId: importFileDetails.credDefId,
fileData: parsedData,
fileName: importFileDetails.fileName
};

const newCacheKey = uuidv4();

await this.cacheManager.set(newCacheKey, JSON.stringify(resData), 3600);
Expand Down
Loading
Loading