Skip to content

Commit

Permalink
Merge pull request #99 from shikshalokam/master
Browse files Browse the repository at this point in the history
entity_generalisation_5.0_changes
  • Loading branch information
aks30 authored Sep 5, 2022
2 parents 9f2ba1e + 74da1ff commit f0d38ec
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 55 deletions.
5 changes: 4 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ KAFKA_GROUP_ID = "projects"

# SUBMISSION TOPIC
SUBMISSION_TOPIC = "dev.sl.projects.submissions" // Kafka topic name for pushing projects submissions
PROJECT_SUBMISSION_TOPIC = "dev.sl.projects.submissions" // project submission topic
PROJECT_SUBMISSION_TOPIC = "dev.sl.projects.submissions" // project submission topic

# SUNBIRD LOCATION AND USER READ
USER_SERVICE_URL = "http://user-service:3000" // service used for user profile read location search are using this base url
3 changes: 2 additions & 1 deletion generics/constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ module.exports = {
"DEFAULT_TASK_COMPLETED" : 0,
"IMAGE_DATA_TYPE" : "image/jpeg",
"DISTRICT": "district",
"SERVER_TIME_OUT" : 5000
"SERVER_TIME_OUT" : 5000,
"OK" : "OK"
};
3 changes: 2 additions & 1 deletion generics/constants/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ module.exports = {
PROJECT_AND_TASK_REPORT : "/v1/improvement-project/projectAndTaskReport",
FILES_DOWNLOADABLE_URL: "/v1/cloud-services/files/getDownloadableUrl",
OBSERVATION_DETAILS : "/v1/observations/details",
USER_READ_V5 : "/v5/user/read"
USER_READ_V5 : "/v5/user/read",
GET_LOCATION_DATA : "/v1/location/search"
};
33 changes: 29 additions & 4 deletions generics/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* author : Aman Karki
* Date : 13-July-2020
* Description : All utility functions.
*/

/**
*/
// Dependencies
const {validate : uuidValidate,v4 : uuidV4} = require('uuid');
/**
* convert camel case to title case.
* @function
* @name camelCaseToTitleCase
Expand Down Expand Up @@ -240,6 +241,29 @@ function revertStatusorNot( appVersion ) {
}

}

/**
* check whether string is valid uuid.
* @function
* @name checkValidUUID
* @param {String} uuids
* @returns {Boolean} returns a Boolean value true/false
*/

function checkValidUUID(uuids) {

var validateUUID = true;
if(Array.isArray(uuids)){
for (var i = 0; uuids.length > i; i++) {
if(!uuidValidate(uuids[i])){
validateUUID = false
}
}
}else {
validateUUID = uuidValidate(uuids);
}
return validateUUID;
}
module.exports = {
camelCaseToTitleCase : camelCaseToTitleCase,
lowerCase : lowerCase,
Expand All @@ -252,5 +276,6 @@ module.exports = {
isValidMongoId : isValidMongoId,
convertProjectStatus : convertProjectStatus,
revertProjectStatus:revertProjectStatus,
revertStatusorNot:revertStatusorNot
revertStatusorNot:revertStatusorNot,
checkValidUUID : checkValidUUID
};
123 changes: 121 additions & 2 deletions generics/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,125 @@ const profile = function ( token,userId = "" ) {
})
}

module.exports = {
profile : profile

/**
*
* @function
* @name locationSearch
* @param {object} filterData - location search filter object.
* @param {Boolean} formatResult - format result or not.
* @returns {Promise} returns a promise.
*/

const locationSearch = function ( filterData, formatResult = false ) {
return new Promise(async (resolve, reject) => {
try {

let bodyData={};
bodyData["request"] = {};
bodyData["request"]["filters"] = filterData;
const url =
userServiceUrl + CONSTANTS.endpoints.GET_LOCATION_DATA;
const options = {
headers : {
"content-type": "application/json"
},
json : bodyData
};

request.post(url,options,requestCallback);

let result = {
success : true
};

function requestCallback(err, data) {
if (err) {
result.success = false;
} else {
let response = data.body;

if( response.responseCode === CONSTANTS.common.OK &&
response.result &&
response.result.response &&
response.result.response.length > 0
) {
if ( formatResult ) {
let entityResult =new Array;
response.result.response.map(entityData => {
let data = {};
data._id = entityData.id;
data.entityType = entityData.type;
data.metaInformation = {};
data.metaInformation.name = entityData.name;
data.metaInformation.externalId = entityData.code
data.registryDetails = {};
data.registryDetails.locationId = entityData.id;
data.registryDetails.code = entityData.code;
entityResult.push(data);
});
result["data"] = entityResult;
result["count"] = response.result.count;
} else {
result["data"] = response.result.response;
result["count"] = response.result.count;
}

} else {
result.success = false;
}
}
return resolve(result);
}

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

} catch (error) {
return reject(error);
}
})
}
/**
* 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,
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 @@ -76,9 +76,6 @@ module.exports = {
entityType : {
type : String
},
entityTypeId : {
type : "ObjectId"
},
taskSequence : {
type : Array,
default : []
Expand Down
2 changes: 1 addition & 1 deletion models/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module.exports = {
default : []
},
entityId : {
type : "ObjectId",
type : String,
index : true
},
programId : {
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
16 changes: 10 additions & 6 deletions module/reports/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ module.exports = class ReportsHelper {
return new Promise(async (resolve, reject) => {
try {
let query = { };

if (entityId) {
query["entityId"] = ObjectId(entityId);
query["entityId"] = entityId;
} else {
query["userId"] = userId
}


let dateRange = await _getDateRangeofReport(reportType);
let endOf = dateRange.endOf;
let startFrom = dateRange.startFrom;
Expand All @@ -70,7 +72,7 @@ module.exports = class ReportsHelper {
[]
);


let tasksReport = {
"total": 0,
"overdue": 0
Expand Down Expand Up @@ -319,6 +321,7 @@ module.exports = class ReportsHelper {
}
} catch (error) {
return resolve({

success: false,
message: error.message,
data: false
Expand Down Expand Up @@ -352,9 +355,9 @@ module.exports = class ReportsHelper {
$exists : true
}
};

if(entityId != "" && UTILS.isValidMongoId(entityId)) {
query.entityId = ObjectId(entityId);
if( entityId != "" ) {
query.entityId = entityId;
}

if (userRole != "") {
Expand Down Expand Up @@ -484,11 +487,12 @@ module.exports = class ReportsHelper {
};

if (entityId) {
query["entityId"] = ObjectId(entityId);
query["entityId"] = entityId;
} else {
query["userId"] = userId
}


let chartObject = [];
let dateRange = await _getDateRangeofReport(reportType);
let endOf = dateRange.endOf;
Expand Down
Loading

0 comments on commit f0d38ec

Please sign in to comment.