Skip to content

Commit

Permalink
Merge pull request #122 from shikshalokam/ED-599-Integration
Browse files Browse the repository at this point in the history
consentShared key added and kafka event trigger conditions updated
  • Loading branch information
aks30 authored May 22, 2023
2 parents 3fe14d3 + 47a9fb3 commit dcc535c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
6 changes: 5 additions & 1 deletion models/programUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ module.exports = {
required: true
},
userRoleInformation: Object,
appInformation: Object
appInformation: Object,
consentShared: {
type: Boolean,
default: false
}
},
compoundIndex: [
{
Expand Down
16 changes: 9 additions & 7 deletions module/programUsers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
35 changes: 24 additions & 11 deletions module/programs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ module.exports = class ProgramsHelper {
});

} catch (error) {
console.log("error :",error)
return resolve({
success : false,
message : error.message,
Expand Down Expand Up @@ -531,7 +530,6 @@ module.exports = class ProgramsHelper {
});

} catch (error) {
console.log("error :",error)
return resolve({
success : false,
message : error.message,
Expand Down Expand Up @@ -980,7 +978,7 @@ module.exports = class ProgramsHelper {
"rootOrganisations"
]
);

if ( !programData.length > 0 ) {
throw ({
status: httpStatusCode.bad_request.status,
Expand All @@ -996,7 +994,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 ) {
Expand All @@ -1019,7 +1017,7 @@ module.exports = class ProgramsHelper {
programId: programId,
userRoleInformation: data.userRoleInformation,
userId: userId,
userProfile:userProfile.data,
userProfile: userProfile.data,
resourcesStarted : false
}
if( appName != "" ) {
Expand Down Expand Up @@ -1049,27 +1047,42 @@ module.exports = class ProgramsHelper {
}
}
let consentResponse = await userService.setUserConsent(userToken, userConsentRequestBody)
console.log("consentResponse ",consentResponse)

if(!consentResponse.success){
throw {
message: constants.apiResponses.PROGRAM_JOIN_FAILED,
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 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 &&
(programUsersDetails.length > 0 && programUsersDetails[0].consentShared === false || !programUsersDetails.length > 0)))) {

pushProgramUsersDetailsToKafka = true;

}

//create or update query
const query = {
programId: programId,
userId: userId
};

//if a resource is started
if ( data.isResource ) {
programUsersData.resourcesStarted = true;
}
//if user interacted with the consent-popup
if ( data.hasOwnProperty('consentShared') ) {
programUsersData.consentShared = data.consentShared;
}
update['$set'] = programUsersData;

// add record to programUsers collection
Expand All @@ -1081,16 +1094,16 @@ module.exports = class ProgramsHelper {
status: httpStatusCode.bad_request.status
}
}
console.log("kafka push status :",pushProgramUsersDetailsToKafka)

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({
Expand Down
6 changes: 4 additions & 2 deletions module/solutions/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions module/users/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dcc535c

Please sign in to comment.