Skip to content

Commit

Permalink
Merge pull request #75 from VISHNUDAS-tunerlabs/hotfix
Browse files Browse the repository at this point in the history
mongoDB index
  • Loading branch information
aks30 authored Mar 24, 2022
2 parents a35b7ce + 7e49caf commit 51306b0
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 57 deletions.
2 changes: 1 addition & 1 deletion controllers/v1/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ module.exports = class Solutions extends Abstract {
* @method
* @name verifyLink
* @param {Object} req - requested data.
* @param {String} req.params._id - solution Id
* @param {String} req.params._id - solution link
* @returns {Array}
*/

Expand Down
9 changes: 5 additions & 4 deletions controllers/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,11 @@ module.exports = class Users extends Abstract {

let currentMaximumCountOfRequiredEntities = 0;
let requiredEntities = new Array;
let roleArray = req.query.role.split(",");

// Calculate required entities for each of the role and send the output of the role which has maximum length.
for (let roleCount = 0; roleCount < req.query.role.split(",").length; roleCount++) {
const eachRole = req.query.role.split(",")[roleCount];
for (let roleCount = 0; roleCount < roleArray.length; roleCount++) {
const eachRole = roleArray[roleCount];
const entitiesMappingData =
await usersHelper.entityTypesByLocationAndRole(
req.params._id,
Expand Down Expand Up @@ -565,8 +566,8 @@ module.exports = class Users extends Abstract {
message: constants.apiResponses.ENTITIES_NOT_ALLOWED_IN_ROLE
};
}

targetedEntities.result = targetedEntity.data;
targetedEntities.result = targetedEntity.data[0];
}
}

Expand Down
13 changes: 10 additions & 3 deletions models/programs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ module.exports = {
name: "programs",
schema: {
externalId: String,
name: String,
description: String,
name: {
type : String,
index : true
},
description: {
type : String,
index : true
},
owner: String,
createdBy: String,
updatedBy: String,
Expand All @@ -20,7 +26,8 @@ module.exports = {
components: ["json"],
isAPrivateProgram : {
default : false,
type : Boolean
type : Boolean,
index : true
},
scope : {
entityType : String,
Expand Down
15 changes: 12 additions & 3 deletions models/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ module.exports = {
schema: {
externalId: String,
isReusable: Boolean,
name: String,
description: String,
name: {
type : String,
index : true
},
description: {
type : String,
index : true
},
author: String,
parentSolutionId: "ObjectId",
resourceType: Array,
Expand Down Expand Up @@ -87,7 +93,10 @@ module.exports = {
},
criteriaLevelReport : Boolean,
license:Object,
link: String,
link: {
type : String,
index : true
},
minNoOfSubmissionsRequired: {
type: Number,
default: 1
Expand Down
4 changes: 3 additions & 1 deletion models/user-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module.exports = {
schema: {
code: {
type: String,
required: true
required: true,
index: true,
unique: true
},
title: {
type: String,
Expand Down
49 changes: 28 additions & 21 deletions module/programs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,29 +498,36 @@ module.exports = class ProgramsHelper {

if ( targetedPrograms.success && targetedPrograms.data && targetedPrograms.data.data.length > 0) {

for (
let targetedProgram = 0;
targetedProgram < targetedPrograms.data.data.length;
targetedProgram ++
) {

let currentTargetedProgram = targetedPrograms.data.data[targetedProgram];

if( currentTargetedProgram.components.length > 0 ) {

let solutions = await solutionsHelper.solutionDocuments({
_id : { $in : currentTargetedProgram.components },
isDeleted : false,
status : constants.common.ACTIVE
},["_id"]);

if( solutions && solutions.length > 0 ) {
currentTargetedProgram["solutions"] = solutions.length;
delete currentTargetedProgram.components;
}
let componentsIds = [];
targetedPrograms.data.data.forEach(targetedProgram => {
if( targetedProgram.components.length > 0 ) {
componentsIds = componentsIds.concat(targetedProgram.components);
}
});

let solutions = await solutionsHelper.solutionDocuments({
_id : { $in : componentsIds },
isDeleted : false,
status : constants.common.ACTIVE
},["_id"]);

const solutionsIds = []
solutions.forEach(solution => solutionsIds.push(solution._id.toString()));

targetedPrograms.data.data.forEach(targetedProgram => {

if( targetedProgram.components.length > 0 ) {

let countSolutions = 0;
targetedProgram.components.forEach(component => {
if (solutionsIds.includes(component.toString())) {
countSolutions++;
}
}
});
targetedProgram.solutions = countSolutions;
delete targetedProgram.components;
}
});
}

return resolve({
Expand Down
28 changes: 12 additions & 16 deletions module/solutions/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1379,15 +1379,13 @@ module.exports = class SolutionsHelper {
}

let targetedSolutions = {
success: false,
success: false
};

let getTargetedSolution = true;

if ( filter === constants.common.DISCOVERED_BY_ME ) {
getTargetedSolution = false;
} else if ( solutionType === constants.common.COURSE ) {
getTargetedSolution = true;
} else if ( gen.utils.convertStringToBoolean(surveyReportPage) === true ) {
getTargetedSolution = false;
}
Expand All @@ -1407,11 +1405,12 @@ module.exports = class SolutionsHelper {

if( targetedSolutions.success ) {

if( targetedSolutions.data.data && targetedSolutions.data.data.length > 0 ) {
totalCount += targetedSolutions.data.count;
targetedSolutions.data.data.forEach(targetedSolution => {
targetedSolution.solutionId = targetedSolution._id;
targetedSolution._id = "";
if( targetedSolutions.success && targetedSolutions.data.data && targetedSolutions.data.data.length > 0 ) {

totalCount += targetedSolutions.data.count;
targetedSolutions.data.data.forEach(targetedSolution => {
targetedSolution.solutionId = targetedSolution._id;
targetedSolution._id = "";

if( solutionType !== constants.common.COURSE ) {
targetedSolution["creator"] = targetedSolution.creator ? targetedSolution.creator : "";
Expand All @@ -1420,7 +1419,7 @@ module.exports = class SolutionsHelper {
if ( solutionType === constants.common.SURVEY ) {
targetedSolution.isCreator = false;
}

mergedData.push(targetedSolution);
delete targetedSolution.type;
delete targetedSolution.externalId;
Expand All @@ -1440,8 +1439,8 @@ module.exports = class SolutionsHelper {
message: constants.apiResponses.TARGETED_OBSERVATION_FETCHED,
data: {
data: mergedData,
count: totalCount,
},
count: totalCount
}
});
} catch (error) {
return reject({
Expand Down Expand Up @@ -1735,10 +1734,6 @@ module.exports = class SolutionsHelper {
verified: false,
};

if ( link == "" ) {
throw new Error(constants.apiResponses.LINK_REQUIRED_CHECK);
}

if ( userToken == "" ) {
throw new Error(constants.apiResponses.REQUIRED_USER_AUTH_TOKEN);
}
Expand Down Expand Up @@ -1798,7 +1793,8 @@ module.exports = class SolutionsHelper {
message: constants.apiResponses.LINK_VERIFIED,
result: response,
});
} catch (error) {
}
catch (error) {
return resolve({
success: false,
status: error.status
Expand Down
25 changes: 17 additions & 8 deletions module/users/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ module.exports = class UsersHelper {
}

const entitiesData = await entitiesHelper.entityDocuments(filterQuery, [
"_id",
"_id", "childHierarchyPath"
]);

if (!entitiesData.length > 0) {
Expand All @@ -623,24 +623,33 @@ module.exports = class UsersHelper {

let entityTypes = [];
let stateEntityExists = false;
let roleEntityType = "";

rolesDocument[0].entityTypes.forEach((roleDocument) => {
if (roleDocument.entityType === constants.common.STATE_ENTITY_TYPE) {
stateEntityExists = true;
}
if (entitiesData[0].childHierarchyPath.includes(roleDocument.entityType)) {
roleEntityType = roleDocument.entityType;
}

});

let entityTypeIndex =
entitiesData[0].childHierarchyPath.findIndex(path => path === roleEntityType);

if (stateEntityExists) {
entityTypes = [constants.common.STATE_ENTITY_TYPE];
} else {
let entitiesMappingForm = await this.entitiesMappingForm(
entitiesData[0]._id,
rolesDocument[0]._id
);
for (
let pointerToChildHierarchy = 0;
pointerToChildHierarchy < entityTypeIndex + 1;
pointerToChildHierarchy++
) {

entitiesMappingForm.result.forEach((entitiesMappingData) => {
entityTypes.push(entitiesMappingData.field);
});
let entityType = entitiesData[0].childHierarchyPath[pointerToChildHierarchy];
entityTypes.push(entityType);
}
}

return resolve({
Expand Down

0 comments on commit 51306b0

Please sign in to comment.