Skip to content

Commit

Permalink
Merge pull request #84 from shikshalokam/master
Browse files Browse the repository at this point in the history
release 4.9 changes
  • Loading branch information
aks30 authored Apr 22, 2022
2 parents d23dc65 + 445304d commit 1cc8bb9
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 35 deletions.
6 changes: 5 additions & 1 deletion controllers/v1/observationSubmissionsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const questionsHelper = require(MODULES_BASE_PATH + "/questions/helper")
const observationSubmissionsHelper = require(MODULES_BASE_PATH + "/observationSubmissions/helper")
const scoringHelper = require(MODULES_BASE_PATH + "/scoring/helper")


/**
* ObservationSubmissions
* @class
Expand Down Expand Up @@ -90,6 +91,7 @@ module.exports = class ObservationSubmissions extends Abstract {
* @param {String} req.params._id -observation solution id.
* @param {String} req.query.entityId -entity id.
* @param {String} req.userDetails.userId - logged in user id.
* @param {String} req.userDetails.userToken - logged in user token.
* @returns {JSON} - observation submissions creation.
*/

Expand Down Expand Up @@ -213,9 +215,11 @@ module.exports = class ObservationSubmissions extends Abstract {
entityProfile: {},
status: "started",
scoringSystem: solutionDocument.scoringSystem,
isRubricDriven: solutionDocument.isRubricDriven
isRubricDriven: solutionDocument.isRubricDriven,
userProfile : observationDocument.userProfile
};


if( solutionDocument.hasOwnProperty("criteriaLevelReport") ) {
submissionDocument["criteriaLevelReport"] = solutionDocument["criteriaLevelReport"];
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/v1/surveysController.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const surveysHelper = require(MODULES_BASE_PATH + "/surveys/helper");
const assessorsHelper = require(MODULES_BASE_PATH + "/entityAssessors/helper");
const solutionsHelper = require(MODULES_BASE_PATH + "/solutions/helper");


/**
* Surveys
* @class
Expand Down Expand Up @@ -638,7 +639,7 @@ module.exports = class Surveys extends Abstract {
let surveyDetails = {};

if( validateSurveyId || req.query.solutionId ) {

let surveyId = req.params._id ? req.params._id : "";

surveyDetails = await surveysHelper.detailsV3
Expand Down
3 changes: 2 additions & 1 deletion generics/httpStatusCodes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = {
},
'ok': {
status: 200,
message: "Success"
message: "Success",
code: "OK"
},
'created': {
status: 201,
Expand Down
3 changes: 2 additions & 1 deletion generics/messageConstants/apiResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,6 @@ module.exports = {
"OBSERVATION_OR_SOLUTION_CHECK" : "Required Observation Id or Solution Id ",
"SOLUTION_NOT_FOUND_OR_NOT_A_TARGETED": "Solution is not targeted to the role",
"OBSERVATION_SUBMISSION_FOUND" : "Observation submission fetched successfully",
"SURVEY_SUBMISSION_FOUND": "Survey submission fetched successfully"
"SURVEY_SUBMISSION_FOUND": "Survey submission fetched successfully",
"SOLUTION_ID_AND_USERPROFILE_REQUIRED": "Required solution Id and userProfile"
}
4 changes: 3 additions & 1 deletion generics/messageConstants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ module.exports = {
CREATED_BY_ME : "createdByMe",
ALL_ROLES : "all",
VERSION_3 : "v3",
DRAFT : "draft"
DRAFT : "draft",
DISTRICT : "district",
SERVER_TIME_OUT : 5000
}
3 changes: 2 additions & 1 deletion generics/messageConstants/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports = {
SOLUTION_DETAILS_BASED_ON_ROLE_LOCATION : "/v1/solutions/detailsBasedOnRoleAndLocation",
GET_PROJECT_TEMPLATE_LISTS : "/v1/project/templates/listByIds",
DOWNLOADABLE_FILE_URL: "/v1/cloud-services/files/getDownloadableUrl",
USER_READ : "/user/v1/read"
USER_READ : "/user/v1/read",
USER_READ_V5 : "/v5/user/read"
}
34 changes: 18 additions & 16 deletions generics/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,44 @@ const profile = function ( token,userId = "" ) {
return new Promise(async (resolve, reject) => {
try {

let url = userServiceUrl + messageConstants.endpoints.USER_READ;

let url = userServiceUrl + messageConstants.endpoints.USER_READ_V5;
if( userId !== "" ) {
url = url + "/" + userId;
url = url + "/" + userId + "?" + "fields=organisations,roles,locations,declarations,externalIds"
}

const options = {
headers : {
"content-type": "application/json",
"x-authenticated-user-token" : token
}
};

request.post(url,options,kendraCallback);

function kendraCallback(err, data) {

let result = {
success : true
};


request.get(url,options,userReadCallback);
let result = {
success : true
};
function userReadCallback(err, data) {

if (err) {
result.success = false;
} else {

let response = JSON.parse(data.body);
if( response.status === HTTP_STATUS_CODE['ok'].status ) {
if( response.responseCode === httpStatusCode['ok'].code ) {
result["data"] = response.result;
} else {
result.success = false;
}

}

return resolve(result);
}
setTimeout(function () {
return resolve (result = {
success : false
});
}, messageConstants.common.SERVER_TIME_OUT);

} catch (error) {
return reject(error);
Expand Down
3 changes: 2 additions & 1 deletion models/observationSubmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports = {
referenceFrom : String,
appInformation : Object,
userRoleInformation : Object,
criteriaLevelReport : Boolean
criteriaLevelReport : Boolean,
userProfile : Object
}
};
1 change: 1 addition & 0 deletions models/observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = {
index: true
},
userRoleInformation : Object,
userProfile : Object,
deleted : {
type : Boolean,
index: true
Expand Down
3 changes: 2 additions & 1 deletion models/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ module.exports = {
minNoOfSubmissionsRequired: {
type: Number,
default: 1
}
},
reportInformation : Object
}
};
3 changes: 2 additions & 1 deletion models/surveySubmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ module.exports = {
description: { type: String, index: true }
},
appInformation : Object,
userRoleInformation : Object
userRoleInformation : Object,
userProfile : Object
}
};

30 changes: 27 additions & 3 deletions module/observations/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const FileStream = require(ROOT_PATH + "/generics/fileStream");
const submissionsHelper = require(MODULES_BASE_PATH + "/submissions/helper");
const programsHelper = require(MODULES_BASE_PATH + "/programs/helper");
const solutionHelper = require(MODULES_BASE_PATH + "/solutions/helper");
const userProfileService = require(ROOT_PATH + "/generics/services/users");

/**
* ObservationsHelper
Expand Down Expand Up @@ -112,6 +113,19 @@ module.exports = class ObservationsHelper {
}
}

//Fetch user profile information by calling sunbird's user read api.
let addReportInfoToSolution = false;
let userProfileData = {};
let userProfile = await userProfileService.profile(requestingUserAuthToken, userId);

if ( userProfile.success &&
userProfile.data &&
userProfile.data.response
) {
userProfileData = userProfile.data.response;
addReportInfoToSolution = true;
}

if( userRoleAndProfileInformation && Object.keys(userRoleAndProfileInformation).length > 0) {

let solutionData =
Expand Down Expand Up @@ -152,9 +166,17 @@ module.exports = class ObservationsHelper {
data,
userId,
solutionData,
userRoleAndProfileInformation
userRoleAndProfileInformation,
userProfileData
);

if ( addReportInfoToSolution && observationData.solutionId ) {
let updateSolution = await solutionHelper.addReportInformationInSolution(
observationData.solutionId,
observationData.userProfile
);
}

return resolve(_.pick(observationData, ["_id", "name", "description"]));

} catch (error) {
Expand All @@ -172,10 +194,11 @@ module.exports = class ObservationsHelper {
* @param {Object} solution - Solution detail data.
* @param {Object} solution - Solution detail data.
* @param {Object} userRoleInformation - user role and profile details.
* @param {Object} userProfileInformation - user profile information.
* @returns {Object} observation creation data.
*/

static createObservation(data,userId,solution,userRoleInformation="") {
static createObservation(data,userId,solution,userRoleInformation="",userProfileInformation = {}) {
return new Promise(async (resolve, reject) => {
try {
if (data.entities) {
Expand Down Expand Up @@ -203,7 +226,8 @@ module.exports = class ObservationsHelper {
"updatedBy": userId,
"createdBy": userId,
"isAPrivateProgram" : solution.isAPrivateProgram,
"userRoleInformation" : userRoleInformation ? userRoleInformation : {}
"userRoleInformation" : userRoleInformation ? userRoleInformation : {},
"userProfile" : userProfileInformation ? userProfileInformation : {}
})
);

Expand Down
80 changes: 80 additions & 0 deletions module/solutions/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,86 @@ module.exports = class SolutionsHelper {
return reject(error);
}
});
}

/**
* Update User District and Organisation In Solutions For Reporting.
* @method
* @name addReportInformationInSolution
* @param {String} solutionId - solution id.
* @param {Object} userProfile - user profile details
* @returns {Object} Solution information.
*/

static addReportInformationInSolution(solutionId,userProfile) {
return new Promise(async (resolve, reject) => {
try {

//check solution & userProfile is exist
if (
solutionId && userProfile &&
userProfile["userLocations"] &&
userProfile["organisations"]
) {

let district = [];
let organisation = [];

//get the districts from the userProfile
for (const location of userProfile["userLocations"]) {
if ( location.type == messageConstants.common.DISTRICT ) {
let distData = {}
distData["locationId"] = location.id;
distData["name"] = location.name;
district.push(distData);
}
}

//get the organisations from the userProfile
for (const org of userProfile["organisations"]) {
let orgData = {};
orgData.orgName = org.orgName;
orgData.organisationId = org.organisationId;
organisation.push(orgData);
}

let updateQuery = {};
updateQuery["$addToSet"] = {};

if ( organisation.length > 0 ) {
updateQuery["$addToSet"]["reportInformation.organisations"] = { $each : organisation};
}

if ( district.length > 0 ) {
updateQuery["$addToSet"]["reportInformation.districts"] = { $each : district};
}

//add user district and organisation in solution
if ( updateQuery["$addToSet"] && Object.keys(updateQuery["$addToSet"].length > 0)) {
await this.updateSolutionDocument
(
{ _id : solutionId },
updateQuery
)
}

} else {
throw new Error(messageConstants.apiResponses.SOLUTION_ID_AND_USERPROFILE_REQUIRED);
}

return resolve({
success: true,
message: messageConstants.apiResponses.UPDATED_DOCUMENT_SUCCESSFULLY
});

} catch (error) {
return resolve({
success : false,
message : error.message,
data: []
});
}
});
}

};
Loading

0 comments on commit 1cc8bb9

Please sign in to comment.