From 250f493426ab3427c587d952c87b711c582100f3 Mon Sep 17 00:00:00 2001 From: Sreejit-K Date: Wed, 6 Mar 2024 19:49:59 +0530 Subject: [PATCH] Added randomMockProfileGeneration logic and neccessary changes for esign UI changes and added Domain_URL variable --- backend/mock-donor-service/config/config.js | 2 +- .../mock-donor-service/config/constants.js | 5 ++-- .../src/routers/abha.router.js | 6 ++-- .../src/routers/esign.router.js | 22 ++++++++------- .../src/services/mock-profile.service.js | 28 ++++++++++++++++++- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/backend/mock-donor-service/config/config.js b/backend/mock-donor-service/config/config.js index 27752ffd..89fe7f1f 100644 --- a/backend/mock-donor-service/config/config.js +++ b/backend/mock-donor-service/config/config.js @@ -1,4 +1,4 @@ -const REDIS_URL = process.env.REDIS_URL; +const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379'; module.exports = { REDIS_URL } \ No newline at end of file diff --git a/backend/mock-donor-service/config/constants.js b/backend/mock-donor-service/config/constants.js index 24f4ba47..5d5cbdfd 100644 --- a/backend/mock-donor-service/config/constants.js +++ b/backend/mock-donor-service/config/constants.js @@ -1,7 +1,8 @@ const HOST = process.env.HOST || 'localhost' const PROTOCOL = process.env.PROTOCOL || 'http' const PORT = process.env.PORT || 5001 +const DOMAIN_URL = process.env.DOMAIN_URL || 'http://localhost:5001' module.exports = { - PROTOCOL, HOST, PORT -} \ No newline at end of file + PROTOCOL, HOST, PORT, DOMAIN_URL +} diff --git a/backend/mock-donor-service/src/routers/abha.router.js b/backend/mock-donor-service/src/routers/abha.router.js index 75ee6505..6596d4af 100644 --- a/backend/mock-donor-service/src/routers/abha.router.js +++ b/backend/mock-donor-service/src/routers/abha.router.js @@ -1,7 +1,7 @@ const express = require('express'); const abhaRouter = express.Router() const {v4: uuidv4} = require('uuid'); -const {getRandomMockProfile, isMockProfilePresent} = require('../services/mock-profile.service'); +const {getRandomMockProfile, isMockProfilePresent, generateRandomABHA} = require('../services/mock-profile.service'); let uuidAbhaMap = new Map(); let userTokenTxnIdMap = new Map(); @@ -60,7 +60,7 @@ abhaRouter.post('/v1/auth/confirmWithMobileOTP', (req, res) => { abhaRouter.get('/v1/account/profile', (req, res) => { const abha = uuidAbhaMap.get(userTokenTxnIdMap.get(req.headers['x-token'].substring(7))); - const profile = getRandomMockProfile(abha); + const profile = getRandomMockProfile(); res.send(profile); }); @@ -74,7 +74,7 @@ abhaRouter.post('/v2/registration/mobile/login/verifyOtp', (req, res) => { res.send({ "mobileLinkedHid": [ { - "healthIdNumber": "91-3075-5157-3552", + "healthIdNumber": generateRandomABHA(), "healthId": "", "name": "John Doe", "profilePhoto": null, diff --git a/backend/mock-donor-service/src/routers/esign.router.js b/backend/mock-donor-service/src/routers/esign.router.js index d2eb14da..2dcbd471 100644 --- a/backend/mock-donor-service/src/routers/esign.router.js +++ b/backend/mock-donor-service/src/routers/esign.router.js @@ -1,20 +1,25 @@ const express = require('express'); const {v4: uuidv4} = require('uuid'); const redis = require('../services/redis.service'); -const { PROTOCOL, HOST, PORT } = require('../../config/constants'); +const { PROTOCOL, HOST, PORT, DOMAIN_URL } = require('../../config/constants'); const esignRouter = express.Router(); esignRouter.post('/digiSign/genEspRequest', (req, res) => { const transactionId = uuidv4(); res.send({ - espUrl: `${PROTOCOL}://${HOST}:${PORT}/mock/esign/${transactionId}`, + espUrl: `${DOMAIN_URL}/mock/esign/${transactionId}`, aspTxnId: transactionId }); return; }); esignRouter.post('/mock/esign/:transactionId', (req, res) => { - const html = `Mock ESign

This is Mock ESIGN Portal

Submit` + const html = `Mock ESign

This is Mock ESIGN Portal

Submit` + res.send(html); +}) + +esignRouter.get('/mock/esign/:transactionId', (req, res) => { + const html = `Mock ESign

This is Mock ESIGN Portal

Submit` res.send(html); }) @@ -24,12 +29,9 @@ esignRouter.get('/mock/esign/submit/:transactionId', async(req, res) => { }); esignRouter.get('/digiSign/pdf/:transactionId', async(req, res) => { - const isSigned = await redis.getKey(req.params.transactionId) === "true"; - if(isSigned) { - res.status(200).json({}); - return; - } - res.sendStatus(404) + // const isSigned = await redis.getKey(req.params.transactionId) === "true"; + res.status(200).json({}); + return; }); esignRouter.post('/api/v1/Pledge/:pledgeOsid/esign/documents', (req, res) => { @@ -38,4 +40,4 @@ esignRouter.post('/api/v1/Pledge/:pledgeOsid/esign/documents', (req, res) => { }) module.exports = { esignRouter -} \ No newline at end of file +} diff --git a/backend/mock-donor-service/src/services/mock-profile.service.js b/backend/mock-donor-service/src/services/mock-profile.service.js index 0af3f0a1..057b702c 100644 --- a/backend/mock-donor-service/src/services/mock-profile.service.js +++ b/backend/mock-donor-service/src/services/mock-profile.service.js @@ -4,6 +4,8 @@ const getRandomMockProfile = (abha = null) => { if(abha === null) { const range = randomProfiles.length; const index = Math.floor(Math.random() * range); + randomProfiles[index]["healthIdNumber"] = generateRandomABHA(); + randomProfiles[index]["mobile"] = generateRandomMobileNumber(); return randomProfiles[index]; } else if(randomProfiles.filter(profile => profile.healthIdNumber.replace(/-/g, '') === abha).length > 0) { return randomProfiles.filter(profile => profile.healthIdNumber.replace(/-/g, '') === abha)[0] @@ -11,6 +13,29 @@ const getRandomMockProfile = (abha = null) => { return null; } + +function generateRandomABHA() { + let result = ''; + // Generate random prefix in the range of 10-99 + const prefix = Math.floor(Math.random() * 90) + 10; + result += prefix + '-'; + // Generate random numbers in the format xxxx-xxxx-xxxx + for (let i = 0; i < 3; i++) { + result += Math.floor(Math.random() * 10000).toString().padStart(4, '0'); + if (i < 2) result += '-'; + } + return result; +} + +function generateRandomMobileNumber() { + let phoneNumber = '9'; // Start with 9 to ensure it's a valid mobile number + for (let i = 1; i < 10; i++) { + phoneNumber += Math.floor(Math.random() * 10); + } + return phoneNumber; +} + + const isMockProfilePresent = (abha) => { return randomProfiles.filter(profile => profile.healthIdNumber.replace(/-/g, '') === abha).length > 0 } @@ -19,5 +44,6 @@ const isMockProfilePresent = (abha) => { module.exports = { getRandomMockProfile, - isMockProfilePresent + isMockProfilePresent, + generateRandomABHA } \ No newline at end of file