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

feat: bulk issuance retry #266

Merged
merged 6 commits into from
Nov 20, 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
6 changes: 0 additions & 6 deletions apps/api-gateway/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ import * as redisStore from 'cache-manager-redis-store';
host: process.env.REDIS_HOST,
port: parseInt(process.env.REDIS_PORT)
}
}),
BullModule.registerQueue({
name: 'bulk-issuance',
redis: {
port: parseInt(process.env.REDIS_PORT)
}
})
],
controllers: [AppController],
Expand Down
8 changes: 8 additions & 0 deletions apps/api-gateway/src/authz/socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ export class SocketGateway implements OnGatewayConnection {
.to(payload.clientId)
.emit('error-in-wallet-creation-process', payload.error);
}

@SubscribeMessage('bulk-issuance-process-completed')
async handleBulkIssuance(payload: ISocketInterface): Promise<void> {
this.logger.log(`bulk-issuance-process-completed ${payload.clientId}`);
this.server
.to(payload.clientId)
.emit('bulk-issuance-process-completed', payload.error);
}
}
3 changes: 2 additions & 1 deletion apps/api-gateway/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ export enum FileUploadType {
export enum FileUploadStatus {
started = 'PROCESS_STARTED',
completed = 'PROCESS_COMPLETED',
interrupted= 'PROCESS INTERRUPTED'
interrupted= 'PROCESS_INTERRUPTED',
retry= 'PROCESS_REINITIATED'
}
8 changes: 8 additions & 0 deletions apps/api-gateway/src/issuance/dtos/issuance.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,12 @@ export class FileParameter {
@Type(() => String)
sortValue = '';

}

export class ClientDetails {
@ApiProperty({ required: false, example: '68y647ayAv79879' })
@IsOptional()
@Type(() => String)
clientId = '';

}
4 changes: 2 additions & 2 deletions apps/api-gateway/src/issuance/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export class IUserOrg {
export interface FileExportResponse {
response: unknown;
fileContent: string;
fileName : string
fileName: string
}

export interface RequestPayload {
credDefId: string;
fileKey: string;
fileName: string;
}
}
46 changes: 38 additions & 8 deletions apps/api-gateway/src/issuance/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { CommonService } from '@credebl/common/common.service';
import { Response } from 'express';
import IResponseType from '@credebl/common/interfaces/response.interface';
import { IssuanceService } from './issuance.service';
import { FileParameter, IssuanceDto, IssueCredentialDto, OutOfBandCredentialDto, PreviewFileDetails } from './dtos/issuance.dto';
import { ClientDetails, FileParameter, IssuanceDto, IssueCredentialDto, OutOfBandCredentialDto, PreviewFileDetails } from './dtos/issuance.dto';
import { IUserRequest } from '@credebl/user-request/user-request.interface';
import { User } from '../authz/decorators/user.decorator';
import { ResponseMessages } from '@credebl/common/response-messages';
Expand Down Expand Up @@ -245,7 +245,7 @@ export class IssuanceController {
const reqPayload: RequestPayload = {
credDefId: credentialDefinitionId,
fileKey,
fileName:file?.filename
fileName: file?.originalname
};
this.logger.log(`reqPayload::::::${JSON.stringify(reqPayload)}`);
const importCsvDetails = await this.issueCredentialService.importCsv(
Expand Down Expand Up @@ -328,6 +328,35 @@ export class IssuanceController {
return res.status(HttpStatus.OK).json(finalResponse);
}

@Post('/orgs/:orgId/:requestId/bulk')
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER)
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@ApiBearerAuth()
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@ApiUnauthorizedResponse({
status: 401,
description: 'Unauthorized',
type: UnauthorizedErrorDto
})
@ApiForbiddenResponse({
status: 403,
description: 'Forbidden',
type: ForbiddenErrorDto
})
@ApiOperation({
summary: 'bulk issue credential',
description: 'bulk issue credential'
})
async issueBulkCredentials(@Param('requestId') requestId: string, @Param('orgId') orgId: number, @Res() res: Response, @Body() clientDetails: ClientDetails): Promise<Response> {
const bulkIssunaceDetails = await this.issueCredentialService.issueBulkCredential(requestId, orgId, clientDetails.clientId);
const finalResponse: IResponseType = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.issuance.success.bulkIssuance,
data: bulkIssunaceDetails.response
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}

@Get('/orgs/:orgId/bulk/files')
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER)
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
Expand Down Expand Up @@ -389,7 +418,7 @@ export class IssuanceController {
};
return res.status(HttpStatus.OK).json(finalResponse);
}

@Get('/orgs/:orgId/:fileId/bulk/file-data')
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER)
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
Expand Down Expand Up @@ -454,7 +483,7 @@ export class IssuanceController {
return res.status(HttpStatus.OK).json(finalResponse);
}

@Post('/orgs/:orgId/:requestId/bulk')
@Post('/orgs/:orgId/:fileId/retry/bulk')
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER)
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@ApiBearerAuth()
Expand All @@ -470,11 +499,11 @@ export class IssuanceController {
type: ForbiddenErrorDto
})
@ApiOperation({
summary: 'bulk issue credential',
description: 'bulk issue credential'
summary: 'Retry bulk issue credential',
description: 'Retry bulk issue credential'
})
async issueBulkCredentials(@Param('requestId') requestId: string, @Param('orgId') orgId: number, @Res() res: Response): Promise<Response> {
const bulkIssunaceDetails = await this.issueCredentialService.issueBulkCredential(requestId, orgId);
async retryBulkCredentials(@Param('fileId') fileId: string, @Param('orgId') orgId: number, @Res() res: Response, @Body() clientDetails: ClientDetails): Promise<Response> {
const bulkIssunaceDetails = await this.issueCredentialService.retryBulkCredential(fileId, orgId, clientDetails.clientId);
const finalResponse: IResponseType = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.issuance.success.bulkIssuance,
Expand All @@ -483,6 +512,7 @@ export class IssuanceController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}


/**
* Description: Issuer send credential to create offer
* @param user
Expand Down
9 changes: 7 additions & 2 deletions apps/api-gateway/src/issuance/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ export class IssuanceService extends BaseService {
return this.sendNats(this.issuanceProxy, 'issued-file-data', payload);
}

async issueBulkCredential(requestId: string, orgId: number): Promise<{ response: object }> {
const payload = { requestId, orgId };
async issueBulkCredential(requestId: string, orgId: number, clientId: string): Promise<{ response: object }> {
const payload = { requestId, orgId, clientId };
return this.sendNats(this.issuanceProxy, 'issue-bulk-credentials', payload);
}

async retryBulkCredential(fileId: string, orgId: number, clientId: string): Promise<{ response: object }> {
const payload = { fileId, orgId, clientId };
return this.sendNats(this.issuanceProxy, 'retry-bulk-credentials', payload);
}
}
4 changes: 3 additions & 1 deletion apps/issuance/interfaces/issuance.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export interface FileUpload {
name?: string;
upload_type?: string;
status?: string;
orgId?: number | string;
orgId?: string;
createDateTime?: Date;
lastChangedDateTime?: Date;
}
Expand All @@ -100,4 +100,6 @@ export interface FileUploadData {
createDateTime: Date;
error?: string;
detailError?: string;
jobId: string;
clientId: string;
}
9 changes: 7 additions & 2 deletions apps/issuance/src/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ export class IssuanceController {


@MessagePattern({ cmd: 'issue-bulk-credentials' })
async issueBulkCredentials(payload: { requestId: string, orgId: number }): Promise<string> {
return this.issuanceService.issueBulkCredential(payload.requestId, payload.orgId);
async issueBulkCredentials(payload: { requestId: string, orgId: number, clientId: string }): Promise<string> {
return this.issuanceService.issueBulkCredential(payload.requestId, payload.orgId, payload.clientId);
}

@MessagePattern({ cmd: 'retry-bulk-credentials' })
async retryeBulkCredentials(payload: { fileId: string, orgId: number, clientId: string }): Promise<string> {
return this.issuanceService.retryBulkCredential(payload.fileId, payload.orgId, payload.clientId);
}
}
11 changes: 1 addition & 10 deletions apps/issuance/src/issuance.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,8 @@ import { AwsService } from '@credebl/aws';
]),
CommonModule,
CacheModule.register({ store: redisStore, host: process.env.REDIS_HOST, port: process.env.REDIS_PORT }),
BullModule.forRoot({
redis: {
host: process.env.REDIS_HOST,
port: parseInt(process.env.REDIS_PORT)
}
}),
BullModule.registerQueue({
name: 'bulk-issuance',
redis: {
port: parseInt(process.env.REDIS_PORT)
}
name: 'bulk-issuance'
})
],
controllers: [IssuanceController],
Expand Down
2 changes: 1 addition & 1 deletion apps/issuance/src/issuance.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export class BulkIssuanceProcessor {
`Processing job ${job.id} of type ${job.name} with data ${JSON.stringify(job.data)}...`
);

this.issuanceService.processIssuanceData(job.data);
await this.issuanceService.processIssuanceData(job.data);
}
}
Loading