Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/credebl/platform into de…
Browse files Browse the repository at this point in the history
…velop-main-bulk-issuances
  • Loading branch information
nishad-ayanworks committed Nov 22, 2023
2 parents 0e4931f + 17d71b6 commit 66129d8
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 45 deletions.
10 changes: 9 additions & 1 deletion apps/api-gateway/src/authz/socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export class SocketGateway implements OnGatewayConnection {
this.logger.log(`bulk-issuance-process-completed ${payload.clientId}`);
this.server
.to(payload.clientId)
.emit('bulk-issuance-process-completed', payload.error);
.emit('bulk-issuance-process-completed');
}

@SubscribeMessage('error-in-bulk-issuance-process')
async handleBulkIssuanceErrorResponse(client:string, payload: ISocketInterface): Promise<void> {
this.logger.log(`error-in-bulk-issuance-process ${payload.clientId}`);
this.server
.to(payload.clientId)
.emit('error-in-bulk-issuance-process', 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 @@ -125,5 +125,6 @@ export enum FileUploadStatus {
started = 'PROCESS_STARTED',
completed = 'PROCESS_COMPLETED',
interrupted= 'PROCESS_INTERRUPTED',
retry= 'PROCESS_REINITIATED'
retry= 'PROCESS_REINITIATED',
partially_completed= 'PARTIALLY_COMPLETED'
}
2 changes: 1 addition & 1 deletion apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class IssuanceRepository {
const { name, status, upload_type, orgId } = fileUploadPayload;
return this.prisma.file_upload.create({
data: {
name,
name: String(name),
orgId: String(orgId),
status,
upload_type
Expand Down
69 changes: 36 additions & 33 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { io } from 'socket.io-client';
@Injectable()
export class IssuanceService {
private readonly logger = new Logger('IssueCredentialService');
private isErrorOccurred: boolean;
constructor(
@Inject('NATS_CLIENT') private readonly issuanceServiceProxy: ClientProxy,
private readonly commonService: CommonService,
Expand All @@ -41,7 +42,8 @@ export class IssuanceService {
private readonly emailData: EmailDto,
private readonly awsService: AwsService,
@InjectQueue('bulk-issuance') private bulkIssuanceQueue: Queue
) { }

) { this.isErrorOccurred = false; }


async sendCredentialCreateOffer(orgId: number, user: IUserRequest, credentialDefinitionId: string, comment: string, connectionId: string, attributes: object[]): Promise<string> {
Expand Down Expand Up @@ -376,6 +378,7 @@ export class IssuanceService {

return allSuccessful;
} catch (error) {

this.logger.error(`[outOfBoundCredentialOffer] - error in create out-of-band credentials: ${JSON.stringify(error)}`);
throw new RpcException(error.response ? error.response : error);
}
Expand Down Expand Up @@ -548,14 +551,14 @@ export class IssuanceService {
};

// Extract and validate emails
const invalidEmails = parsedData.data.filter((entry) => !validateEmail(entry.email));
const invalidEmails = parsedData.data.filter((entry) => !validateEmail(entry.email));

// Output invalid emails
if (0 < invalidEmails.length) {
throw new BadRequestException(`Invalid emails found in the chosen file`);
}
// Output invalid emails
if (0 < invalidEmails.length) {

throw new BadRequestException(`Invalid emails found in the chosen file`);

}

const fileData: string[] = parsedData.data.map(Object.values);
const fileHeader: string[] = parsedData.meta.fields;
Expand Down Expand Up @@ -781,16 +784,13 @@ if (0 < invalidEmails.length) {

async retryBulkCredential(fileId: string, orgId: number, clientId: string): Promise<string> {
let respFile;
let respFileUpload;

try {

const fileDetails = await this.issuanceRepository.getFileDetailsById(fileId);
if (!fileDetails) {
throw new BadRequestException(ResponseMessages.issuance.error.retry);
}

respFileUpload = await this.issuanceRepository.updateFileUploadStatus(fileId);
respFile = await this.issuanceRepository.getFailedCredentials(fileId);

if (0 === respFile.length) {
Expand All @@ -813,7 +813,7 @@ if (0 < invalidEmails.length) {
isLastData: respFile.indexOf(element) === respFile.length - 1
};

await this.processIssuanceData(payload);
this.processIssuanceData(payload);
} catch (error) {
// Handle errors if needed
this.logger.error(`Error processing issuance data: ${error}`);
Expand All @@ -823,21 +823,12 @@ if (0 < invalidEmails.length) {
return 'Process reinitiated for bulk issuance';
} catch (error) {
throw new RpcException(error.response ? error.response : error);
} finally {
// Update file upload details in the database
if (respFileUpload && respFileUpload.id) {
const fileUpload = {
status: FileUploadStatus.interrupted,
lastChangedDateTime: new Date()
};

await this.issuanceRepository.updateFileUploadDetails(respFileUpload.id, fileUpload);
}
}
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
async processIssuanceData(jobDetails) {

const socket = await io(`${process.env.SOCKET_HOST}`, {
reconnection: true,
reconnectionDelay: 5000,
Expand All @@ -864,8 +855,10 @@ if (0 < invalidEmails.length) {
fileUploadData.createDateTime = new Date();
fileUploadData.referenceId = jobDetails.data.email;
fileUploadData.jobId = jobDetails.id;
try {

let isErrorOccurred = false;
try {

const oobIssuancepayload = {
credentialDefinitionId: jobDetails.credentialDefinitionId,
orgId: jobDetails.orgId,
Expand Down Expand Up @@ -893,31 +886,41 @@ if (0 < invalidEmails.length) {
fileUploadData.isError = true;
fileUploadData.error = JSON.stringify(error.error) ? JSON.stringify(error.error) : JSON.stringify(error);
fileUploadData.detailError = `${JSON.stringify(error)}`;
if (!isErrorOccurred) {
isErrorOccurred = true;
socket.emit('error-in-bulk-issuance-process', { clientId: jobDetails.clientId, error });
}

}
await this.issuanceRepository.updateFileUploadData(fileUploadData);

try {
if (jobDetails.isLastData) {
const errorCount = await this.issuanceRepository.countErrorsForFile(jobDetails.fileUploadId);
const status =
0 === errorCount ? FileUploadStatus.completed : FileUploadStatus.partially_completed;

if (!jobDetails.isRetry) {
this.cacheManager.del(jobDetails.cacheId);
await this.issuanceRepository.updateFileUploadDetails(jobDetails.fileUploadId, {
status: FileUploadStatus.completed,
lastChangedDateTime: new Date()
});
} else {
await this.issuanceRepository.updateFileUploadDetails(jobDetails.fileUploadId, {
status: FileUploadStatus.completed,
lastChangedDateTime: new Date()
});
}

await this.issuanceRepository.updateFileUploadDetails(jobDetails.fileUploadId, {
status,
lastChangedDateTime: new Date()
});

this.logger.log(`jobDetails.clientId----${JSON.stringify(jobDetails.clientId)}`);

socket.emit('bulk-issuance-process-completed', { clientId: jobDetails.clientId });
}
} catch (error) {
this.logger.error(`Error completing bulk issuance process: ${error}`);
this.logger.error(`Error in completing bulk issuance process: ${error}`);
if (!isErrorOccurred) {
isErrorOccurred = true;
socket.emit('error-in-bulk-issuance-process', { clientId: jobDetails.clientId, error });
}
throw error;

}

}
Expand Down
5 changes: 3 additions & 2 deletions apps/user/src/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export class UserService {

const imageUrl = await this.awsService.uploadUserCertificate(
imageBuffer,
'png',
'svg',
verifyCode,
'certificates',
'base64'
Expand Down Expand Up @@ -619,10 +619,11 @@ export class UserService {
const browser = await puppeteer.launch({
executablePath: '/usr/bin/google-chrome',
args: ['--no-sandbox', '--disable-setuid-sandbox'],
protocolTimeout: 200000,
headless: true
});
const page = await browser.newPage();
await page.setViewport({ width: 800, height: 1020, deviceScaleFactor: 6});
await page.setViewport({ width: 0, height: 1000, deviceScaleFactor: 2});
await page.setContent(template);
const screenshot = await page.screenshot();
await browser.close();
Expand Down
5 changes: 3 additions & 2 deletions apps/user/templates/arbiter-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ArbiterTemplate {
<body>
<div id="container" style="">
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.png" alt="background"
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.svg" alt="background"
style="height: 1000px; width: 770px;"
/>
<div id="textOverlay" style="width: 760px; height: 450px;">
Expand All @@ -62,7 +62,7 @@ export class ArbiterTemplate {
</div>
<p style="font-size: 15px; font-family: Inter;margin: 15; margin-top: 15px;">IS PROUDLY PRESENTED TO</p>
<p style="font-size: 35px; font-style: italic; ">${name}</p>
<p style="font-size: 35px; font-style: italic; margin: 0">${name}</p>
<span >
<p style="font-size: 16px; " >has served as an Arbiter at the
Expand All @@ -78,6 +78,7 @@ export class ArbiterTemplate {
</p>
<div style="font-family: Inter; font-weight: bold; font-size: 12px;">Date: 24, 25, 26 November 2023 | Place: Cidco Exhibition Centre, Navi Mumbai, ${country}</div>
<div style="font-family: Inter; font-weight: bold; font-size: 12px; margin-top:316px">Blockchain-based certificate issued using "credebl.id", by Blockster Labs Pvt. Ltd.</div>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions apps/user/templates/participant-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export class ParticipantTemplate {
<body>
<div id="container" style="">
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.png" alt="background"
style="height: 1000px; width: 770px;"
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.svg" alt="background"
style="height: 1000px; width: 770px;"
/>
<div id="textOverlay" style="width: 760px; height: 450px;">
<div>
Expand All @@ -74,6 +74,7 @@ export class ParticipantTemplate {
<p style="font-size: 14px; margin: 0;">exceptional memory skills demonstrated during the competition.</p>
</p>
<div style="font-family: Inter; font-weight: bold; font-size: 12px;">Date: 24, 25, 26 November 2023 | Place: Cidco Exhibition Centre, Navi Mumbai, ${country}</div>
<div style="font-family: Inter; font-weight: bold; font-size: 12px; margin-top:316px">Blockchain-based certificate issued using "credebl.id", by Blockster Labs Pvt. Ltd.</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion apps/user/templates/winner-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class WinnerTemplate {
<body>
<div id="container" style="">
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.png" alt="background"
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.svg" alt="background"
style="height: 1000px; width: 770px;"/>
<div id="textOverlay" style="width: 780px; height: 450px;">
<div>
Expand All @@ -78,6 +78,7 @@ export class WinnerTemplate {
<p style="font-size: 14px; margin: 0;">exceptional memory skills demonstrated during the competition.</p>
</p>
<div style="font-family: Inter; font-weight: bold; font-size: 12px;">Date: 24, 25, 26 November 2023 | Place: Cidco Exhibition Centre, Navi Mumbai, ${country}</div>
<div style="font-family: Inter; font-weight: bold; font-size: 12px; margin-top:316px">Blockchain-based certificate issued using "credebl.id", by Blockster Labs Pvt. Ltd.</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion apps/user/templates/world-record-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class WorldRecordTemplate {
<body>
<div id="container" style="">
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.png" alt="background"
<img id="backgroundImage" src="https://credebl-dev-user-certificate.s3.ap-south-1.amazonaws.com/certificates/background_image.svg" alt="background"
style="height: 1000px; width: 770px;"
/>
<div id="textOverlay" style="width: 760px; height: 450px;">
Expand All @@ -76,6 +76,7 @@ export class WorldRecordTemplate {
<p style="font-size: 14px; margin: 0;">exceptional memory skills demonstrated during the competition.</p>
</p>
<div style="font-family: Inter; font-weight: bold; font-size: 12px;">Date: 24, 25, 26 November 2023 | Place: Cidco Exhibition Centre, Navi Mumbai, ${country}</div>
<div style="font-family: Inter; font-weight: bold; font-size: 12px; margin-top:316px">Blockchain-based certificate issued using "credebl.id", by Blockster Labs Pvt. Ltd.</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion libs/aws/src/aws.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AwsService {
Key: `${pathAWS}/${encodeURIComponent(filename)}.${timestamp}.${ext}`,
Body: fileBuffer,
ContentEncoding: encoding,
ContentType: `image/png`
ContentType: `image/svg`
});
return `https://${process.env.AWS_PUBLIC_BUCKET_NAME}.s3.${process.env.AWS_PUBLIC_REGION}.amazonaws.com/${pathAWS}/${encodeURIComponent(filename)}.${timestamp}.${ext}`;
} catch (err) {
Expand Down

0 comments on commit 66129d8

Please sign in to comment.