Skip to content

Commit

Permalink
Merge pull request #95 from shikshalokam/5.0-entity-generalization
Browse files Browse the repository at this point in the history
hierarchy added,
  • Loading branch information
aks30 authored Sep 4, 2022
2 parents 6ced1e1 + 179ce15 commit 74da1ff
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
38 changes: 37 additions & 1 deletion generics/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,43 @@ const locationSearch = function ( filterData, formatResult = false ) {
}
})
}
/**
* get Parent Entities of an entity.
* @method
* @name getParentEntities
* @param {String} entityId - entity id
* @returns {Array} - parent entities.
*/

async function getParentEntities( entityId, iteration = 0, parentEntities ) {

if ( iteration == 0 ) {
parentEntities = [];
}

let filterQuery = {
"id" : entityId
};

let entityDetails = await locationSearch(filterQuery);
if ( !entityDetails.success ) {
return parentEntities;
} else {

let entityData = entityDetails.data[0];
if ( iteration > 0 ) parentEntities.push(entityData);
if ( entityData.parentId ) {
iteration = iteration + 1;
entityId = entityData.parentId;
await getParentEntities(entityId, iteration, parentEntities);
}
}

return parentEntities;

}
module.exports = {
profile : profile,
locationSearch : locationSearch
locationSearch : locationSearch,
getParentEntities : getParentEntities
};
1 change: 0 additions & 1 deletion models/programs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module.exports = {
},
scope : {
entityType : String,
entityTypeId : "ObjectId",
entities : {
type : Array,
index : true
Expand Down
3 changes: 0 additions & 3 deletions models/project-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ module.exports = {
entityType : {
type : String
},
entityTypeId : {
type : "ObjectId"
},
taskSequence : {
type : Array,
default : []
Expand Down
2 changes: 0 additions & 2 deletions models/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = {
themes: Array,
flattenedThemes : Array,
questionSequenceByEcm: Object,
entityTypeId: "ObjectId",
entityType: String,
type: String,
subType: String,
Expand Down Expand Up @@ -74,7 +73,6 @@ module.exports = {
referenceFrom : String,
scope : {
entityType : String,
entityTypeId : "ObjectId",
entities : {
type : Array,
index : true
Expand Down
1 change: 0 additions & 1 deletion module/project/templates/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ module.exports = class ProjectTemplatesHelper {

if( parsedData.entityType && parsedData.entityType !== "" ) {
parsedData.entityType = csvInformation.entityTypes[parsedData.entityType].name;
parsedData.entityTypeId = csvInformation.entityTypes[parsedData.entityType]._id;
}

let learningResources =
Expand Down
25 changes: 15 additions & 10 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ module.exports = class UserProjectsHelper {
return resolve(entityInformation);
}

projectCreation.data["entityInformation"] = _entitiesMetaInformation(
projectCreation.data["entityInformation"] = await _entitiesMetaInformation(
entityInformation.data
)[0];

Expand Down Expand Up @@ -2716,9 +2716,9 @@ function _entitiesInformation(entityIds) {
}
let entitiesData = [];
if ( entityInformations.length > 0 ) {
entitiesData = _entitiesMetaInformation(entityInformations);
entitiesData = await _entitiesMetaInformation(entityInformations);
}

return resolve({
success: true,
data: entitiesData
Expand Down Expand Up @@ -2985,13 +2985,18 @@ function _observationDetails(observationData, userRoleAndProfileInformation = {}
*/

function _entitiesMetaInformation(entitiesData) {
entitiesData = entitiesData.map(entity => {
entity.metaInformation._id = entity._id;
entity.metaInformation.entityType = entity.entityType;
entity.metaInformation.registryDetails = entity.registryDetails;
return entity.metaInformation;
});
return entitiesData;
return new Promise(async (resolve, reject) => {
let entityInformation = []
for ( let index = 0; index < entitiesData.length; index++ ) {
let entityHierarchy = await userProfileService.getParentEntities( entitiesData[index]._id );
entitiesData[index].metaInformation.hierarchy = entityHierarchy;
entitiesData[index].metaInformation._id = entitiesData[index]._id;
entitiesData[index].metaInformation.entityType = entitiesData[index].entityType;
entitiesData[index].metaInformation.registryDetails = entitiesData[index].registryDetails;
entityInformation.push(entitiesData[index].metaInformation)
}
return resolve (entityInformation);
})
}


Expand Down

0 comments on commit 74da1ff

Please sign in to comment.