From 6ecc6977d2c613965b06666f6f1d61217f597e33 Mon Sep 17 00:00:00 2001 From: pallavicoder Date: Tue, 21 Nov 2023 22:48:46 +0530 Subject: [PATCH 1/3] refact:added function for validating emails from uploaded file in bulk issuance API Signed-off-by: pallavicoder --- apps/issuance/src/issuance.service.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/issuance/src/issuance.service.ts b/apps/issuance/src/issuance.service.ts index 36944abd9..939434ca8 100644 --- a/apps/issuance/src/issuance.service.ts +++ b/apps/issuance/src/issuance.service.ts @@ -540,6 +540,23 @@ export class IssuanceService { throw new BadRequestException(`File header is empty`); } + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + const validateEmail = (email) => { + // Regular expression for a simple email validation + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailRegex.test(email); + }; + + // Extract and validate emails +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`); + +} + const fileData: string[] = parsedData.data.map(Object.values); const fileHeader: string[] = parsedData.meta.fields; From 91b34c7cc06829c4c6bef9059fa1884f75565f66 Mon Sep 17 00:00:00 2001 From: pallavicoder Date: Tue, 21 Nov 2023 23:33:45 +0530 Subject: [PATCH 2/3] refact:changed email regex pattern Signed-off-by: pallavicoder --- apps/issuance/src/issuance.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/issuance/src/issuance.service.ts b/apps/issuance/src/issuance.service.ts index 939434ca8..d8e4842c0 100644 --- a/apps/issuance/src/issuance.service.ts +++ b/apps/issuance/src/issuance.service.ts @@ -543,7 +543,7 @@ export class IssuanceService { // eslint-disable-next-line @typescript-eslint/explicit-function-return-type const validateEmail = (email) => { // Regular expression for a simple email validation - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return emailRegex.test(email); }; From d2c1f5b392df2a48ce7e0075e3de17401064b609 Mon Sep 17 00:00:00 2001 From: Nishad Date: Wed, 22 Nov 2023 01:44:20 +0530 Subject: [PATCH 3/3] updated package json for cache manager redis Signed-off-by: Nishad --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 5da437495..426b0aef1 100755 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "dependencies": { "@nestjs/axios": "^3.0.0", "@nestjs/bull": "^10.0.1", + "@nestjs/cache-manager": "^2.1.0", "@nestjs/common": "^10.2.7", "@nestjs/config": "^3.0.0", "@nestjs/core": "^10.1.3", @@ -55,6 +56,8 @@ "body-parser": "^1.20.1", "buffer": "^6.0.3", "bull": "^4.11.4", + "cache-manager": "^5.2.4", + "cache-manager-redis-store": "^2.0.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "crypto-js": "^4.1.1",