From 8901499358422e5a9585fc178e027f58501db03b Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Fri, 19 May 2023 16:18:43 +0530 Subject: [PATCH 1/4] consentShared key added and kafka event trigger conditions updated --- models/programUsers.js | 6 +++++- module/programs/helper.js | 31 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/models/programUsers.js b/models/programUsers.js index b6115dd4..dbcbcd91 100644 --- a/models/programUsers.js +++ b/models/programUsers.js @@ -21,7 +21,11 @@ module.exports = { required: true }, userRoleInformation: Object, - appInformation: Object + appInformation: Object, + consentShared: { + type: Boolean, + default: false + } }, compoundIndex: [ { diff --git a/module/programs/helper.js b/module/programs/helper.js index f791fa9a..5c26992d 100644 --- a/module/programs/helper.js +++ b/module/programs/helper.js @@ -980,7 +980,7 @@ module.exports = class ProgramsHelper { "rootOrganisations" ] ); - + if ( !programData.length > 0 ) { throw ({ status: httpStatusCode.bad_request.status, @@ -996,7 +996,7 @@ module.exports = class ProgramsHelper { userId: userId, programId: programId }, - ["_id"] + ["_id","consentShared"] ); // if user not joined for program. we have add more key values to programUsersData if ( !programUsersDetails.length > 0 ) { @@ -1019,7 +1019,7 @@ module.exports = class ProgramsHelper { programId: programId, userRoleInformation: data.userRoleInformation, userId: userId, - userProfile:userProfile.data, + userProfile: userProfile.data, resourcesStarted : false } if( appName != "" ) { @@ -1057,8 +1057,16 @@ module.exports = class ProgramsHelper { status: httpStatusCode.bad_request.status } } + } - pushProgramUsersDetailsToKafka = true; + + } + + // if requestForPIIConsent Is false and user not joined program till now then set pushProgramUsersDetailsToKafka = true; + // if requestForPIIConsent == true and data.consentShared value is true which means user interacted with the consent popup set pushProgramUsersDetailsToKafka = true; + if((programData[0].hasOwnProperty('requestForPIIConsent') && programData[0].requestForPIIConsent === false && !programUsersDetails.length > 0) || + ((programData[0].hasOwnProperty('requestForPIIConsent') && programData[0].requestForPIIConsent === true) && (data.hasOwnProperty('consentShared') && data.consentShared == true) ) ){ + pushProgramUsersDetailsToKafka = true; } //create or update query @@ -1066,10 +1074,14 @@ module.exports = class ProgramsHelper { programId: programId, userId: userId }; - + //if a resource is started if ( data.isResource ) { programUsersData.resourcesStarted = true; } + //if user interacted with the consent-popup + if ( data.consentShared ) { + programUsersData.consentShared = true; + } update['$set'] = programUsersData; // add record to programUsers collection @@ -1081,14 +1093,17 @@ module.exports = class ProgramsHelper { status: httpStatusCode.bad_request.status } } - console.log("kafka push status :",pushProgramUsersDetailsToKafka) + let joinProgramDetails = joinProgram.toObject(); - + // if programUsersDetails[0].consentShared === true which means the data is already pushed to Kafka once, So revert pushProgramUsersDetailsToKafka to false + if (programUsersDetails.length > 0 && programUsersDetails[0].hasOwnProperty('consentShared') && programUsersDetails[0].consentShared === true) { + pushProgramUsersDetailsToKafka = false; + } + console.log("kafka push status :",pushProgramUsersDetailsToKafka) if ( pushProgramUsersDetailsToKafka ) { joinProgramDetails.programName = programData[0].name; joinProgramDetails.programExternalId = programData[0].externalId; joinProgramDetails.requestForPIIConsent = programData[0].requestForPIIConsent; - // push programUsers details to kafka await kafkaProducersHelper.pushProgramUsersToKafka(joinProgramDetails); } From af5422c4fe41c24945589bc38524f31d2e4aed9d Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Sat, 20 May 2023 08:51:05 +0530 Subject: [PATCH 2/4] changes added to pass consentShared value to front end --- module/programUsers/helper.js | 16 +++++++++------- module/programs/helper.js | 5 +---- module/solutions/helper.js | 6 ++++-- module/users/helper.js | 6 ++++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/module/programUsers/helper.js b/module/programUsers/helper.js index 39f15f1b..3429474b 100644 --- a/module/programUsers/helper.js +++ b/module/programUsers/helper.js @@ -120,20 +120,21 @@ module.exports = class ProgramUsersHelper { } /** - * check if user joined a program or not + * check if user joined a program or not and consentShared * @method - * @name checkForUserJoinedProgram + * @name checkForUserJoinedProgramAndConsentShared * @param {String} programId * @param {String} userId - * @returns {Boolean} - true/false. + * @returns {Object} result. */ - static checkForUserJoinedProgram( + static checkForUserJoinedProgramAndConsentShared( programId, userId ) { return new Promise(async (resolve, reject) => { try { + let result = {}; const query = { userId: userId, programId: programId @@ -142,10 +143,11 @@ module.exports = class ProgramUsersHelper { //Check data present in programUsers collection. let programUsers = await this.programUsersDocuments( query, - ["_id"] + ["_id","consentShared"] ); - let joinedProgram = programUsers.length > 0 ? true :false - return resolve(joinedProgram); + result.joinProgram = programUsers.length > 0 ? true : false; + result.consentShared = programUsers.length > 0 ? programUsers[0].consentShared : false; + return resolve(result); } catch (error) { return reject(error); diff --git a/module/programs/helper.js b/module/programs/helper.js index 5c26992d..3d39bfcb 100644 --- a/module/programs/helper.js +++ b/module/programs/helper.js @@ -477,7 +477,6 @@ module.exports = class ProgramsHelper { }); } catch (error) { - console.log("error :",error) return resolve({ success : false, message : error.message, @@ -531,7 +530,6 @@ module.exports = class ProgramsHelper { }); } catch (error) { - console.log("error :",error) return resolve({ success : false, message : error.message, @@ -1049,7 +1047,6 @@ module.exports = class ProgramsHelper { } } let consentResponse = await userService.setUserConsent(userToken, userConsentRequestBody) - console.log("consentResponse ",consentResponse) if(!consentResponse.success){ throw { @@ -1099,7 +1096,7 @@ module.exports = class ProgramsHelper { if (programUsersDetails.length > 0 && programUsersDetails[0].hasOwnProperty('consentShared') && programUsersDetails[0].consentShared === true) { pushProgramUsersDetailsToKafka = false; } - console.log("kafka push status :",pushProgramUsersDetailsToKafka) + if ( pushProgramUsersDetailsToKafka ) { joinProgramDetails.programName = programData[0].name; joinProgramDetails.programExternalId = programData[0].externalId; diff --git a/module/solutions/helper.js b/module/solutions/helper.js index d590b230..798b10a6 100644 --- a/module/solutions/helper.js +++ b/module/solutions/helper.js @@ -2015,8 +2015,10 @@ module.exports = class SolutionsHelper { } //Check data present in programUsers collection. - //checkForUserJoinedProgram will check for data and if its present return true else false. - templateOrQuestionDetails.result.programJoined = await programUsersHelper.checkForUserJoinedProgram(solutionData.programId,userId); + //checkForUserJoinedProgramAndConsentShared will returns an object which contain joinProgram and consentShared status + let programJoinStatus = await programUsersHelper.checkForUserJoinedProgramAndConsentShared(solutionData.programId,userId); + templateOrQuestionDetails.result.programJoined = programJoinStatus.joinProgram; + templateOrQuestionDetails.result.consentShared = programJoinStatus.consentShared; return resolve(templateOrQuestionDetails); diff --git a/module/users/helper.js b/module/users/helper.js index 2ee84e70..89ab1492 100644 --- a/module/users/helper.js +++ b/module/users/helper.js @@ -594,8 +594,10 @@ module.exports = class UsersHelper { result.requestForPIIConsent = programData[0].requestForPIIConsent; } //Check data present in programUsers collection. - //checkForUserJoinedProgram will check for data and if its present return true else false. - result.programJoined = await programUsersHelper.checkForUserJoinedProgram(programId,userId); + //checkForUserJoinedProgramAndConsentShared will returns an object which contain joinProgram and consentShared status. + let programJoinStatus = await programUsersHelper.checkForUserJoinedProgramAndConsentShared(programId,userId); + result.programJoined = programJoinStatus.joinProgram; + result.consentShared = programJoinStatus.consentShared; return resolve({ message: constants.apiResponses.PROGRAM_SOLUTIONS_FETCHED, From f3e992888500444e67618b96655ee26f65c5992a Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Mon, 22 May 2023 08:07:31 +0530 Subject: [PATCH 3/4] pushProgramUsersDetailsToKafka determining codeblock change --- module/programs/helper.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/module/programs/helper.js b/module/programs/helper.js index 3d39bfcb..1dd185a5 100644 --- a/module/programs/helper.js +++ b/module/programs/helper.js @@ -1063,7 +1063,13 @@ module.exports = class ProgramsHelper { // if requestForPIIConsent == true and data.consentShared value is true which means user interacted with the consent popup set pushProgramUsersDetailsToKafka = true; if((programData[0].hasOwnProperty('requestForPIIConsent') && programData[0].requestForPIIConsent === false && !programUsersDetails.length > 0) || ((programData[0].hasOwnProperty('requestForPIIConsent') && programData[0].requestForPIIConsent === true) && (data.hasOwnProperty('consentShared') && data.consentShared == true) ) ){ + pushProgramUsersDetailsToKafka = true; + + // if programUsersDetails[0].consentShared === true which means the data is already pushed to Kafka once, So revert pushProgramUsersDetailsToKafka to false + if (programUsersDetails.length > 0 && programUsersDetails[0].hasOwnProperty('consentShared') && programUsersDetails[0].consentShared === true) { + pushProgramUsersDetailsToKafka = false; + } } //create or update query @@ -1092,11 +1098,7 @@ module.exports = class ProgramsHelper { } let joinProgramDetails = joinProgram.toObject(); - // if programUsersDetails[0].consentShared === true which means the data is already pushed to Kafka once, So revert pushProgramUsersDetailsToKafka to false - if (programUsersDetails.length > 0 && programUsersDetails[0].hasOwnProperty('consentShared') && programUsersDetails[0].consentShared === true) { - pushProgramUsersDetailsToKafka = false; - } - + if ( pushProgramUsersDetailsToKafka ) { joinProgramDetails.programName = programData[0].name; joinProgramDetails.programExternalId = programData[0].externalId; From 47a9fb31bd0f13b6a0fa5388020251cc24468166 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Mon, 22 May 2023 11:34:01 +0530 Subject: [PATCH 4/4] added changes to check pushProgramUsersDetailsToKafka==true in single if condition --- module/programs/helper.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/module/programs/helper.js b/module/programs/helper.js index 1dd185a5..f71fc0f4 100644 --- a/module/programs/helper.js +++ b/module/programs/helper.js @@ -1061,15 +1061,13 @@ module.exports = class ProgramsHelper { // if requestForPIIConsent Is false and user not joined program till now then set pushProgramUsersDetailsToKafka = true; // if requestForPIIConsent == true and data.consentShared value is true which means user interacted with the consent popup set pushProgramUsersDetailsToKafka = true; + // if programUsersDetails[0].consentShared === true which means the data is already pushed to Kafka once if((programData[0].hasOwnProperty('requestForPIIConsent') && programData[0].requestForPIIConsent === false && !programUsersDetails.length > 0) || - ((programData[0].hasOwnProperty('requestForPIIConsent') && programData[0].requestForPIIConsent === true) && (data.hasOwnProperty('consentShared') && data.consentShared == true) ) ){ + ((programData[0].hasOwnProperty('requestForPIIConsent') && programData[0].requestForPIIConsent === true) && (data.hasOwnProperty('consentShared') && data.consentShared == true && + (programUsersDetails.length > 0 && programUsersDetails[0].consentShared === false || !programUsersDetails.length > 0)))) { pushProgramUsersDetailsToKafka = true; - - // if programUsersDetails[0].consentShared === true which means the data is already pushed to Kafka once, So revert pushProgramUsersDetailsToKafka to false - if (programUsersDetails.length > 0 && programUsersDetails[0].hasOwnProperty('consentShared') && programUsersDetails[0].consentShared === true) { - pushProgramUsersDetailsToKafka = false; - } + } //create or update query @@ -1082,8 +1080,8 @@ module.exports = class ProgramsHelper { programUsersData.resourcesStarted = true; } //if user interacted with the consent-popup - if ( data.consentShared ) { - programUsersData.consentShared = true; + if ( data.hasOwnProperty('consentShared') ) { + programUsersData.consentShared = data.consentShared; } update['$set'] = programUsersData; @@ -1098,13 +1096,14 @@ module.exports = class ProgramsHelper { } let joinProgramDetails = joinProgram.toObject(); - + if ( pushProgramUsersDetailsToKafka ) { joinProgramDetails.programName = programData[0].name; joinProgramDetails.programExternalId = programData[0].externalId; joinProgramDetails.requestForPIIConsent = programData[0].requestForPIIConsent; // push programUsers details to kafka await kafkaProducersHelper.pushProgramUsersToKafka(joinProgramDetails); + } return resolve({