From d6c850d0c73145d115e8681b1accfa5bdc041ac7 Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Tue, 22 Feb 2022 10:19:07 +0530 Subject: [PATCH 01/15] cache file --- generics/helpers/cache.js | 62 +++++++++++++++++++++++++++++++++++++++ package.json | 9 +++--- 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 generics/helpers/cache.js diff --git a/generics/helpers/cache.js b/generics/helpers/cache.js new file mode 100644 index 00000000..603d1a29 --- /dev/null +++ b/generics/helpers/cache.js @@ -0,0 +1,62 @@ +/** + * name : cache.js + * author : Priyanka Pradeep + * created-date : 21-Feb-2020 + * Description : Cache set , get and remove functionality. + */ + + const nodeCache = require( "node-cache" ); + const cache = new nodeCache(); + + /** + * Get cache data. + * @method + * @name get - Get specific cache data + * @params key - name of the cache key. + * @returns {Array} - return specific cache data. +*/ + +function getValue(key){ + let data = []; + + if (cache.has(key)) { + data = cache.get(key); + } + + return data; +} + + + /** + * Set new cache data + * @method + * @name set + * @params key - name of the cache key. + * @params value - cache data to set. + * @returns {Array} - cache updated data. +*/ + +function setValue(key, value, timeout){ + let data = cache.set( key, value, timeout ); + return data; +} + +/** + * delete cache data + * @method + * @name remove + * @params key - cache key need to be removed. + * @returns +*/ + +function removeKey(key){ + + let data = cache.del(key); + return; +} + +module.exports = { + getValue : getValue, + setValue : setValue, + removeKey : removeKey +} \ No newline at end of file diff --git a/package.json b/package.json index a7afd220..ab919560 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,8 @@ "bunyan": "^1.8.12", "bunyan-format": "^0.2.1", "cache-manager": "^3.1.0", + "chai": "^4.2.0", + "chai-http": "^4.3.0", "cli-table": "^0.3.1", "cors": "^2.8.5", "csvtojson": "^2.0.10", @@ -49,21 +51,20 @@ "keycloak-auth-utils": "^3.3.0", "lodash": "^4.17.15", "log": "^1.4.0", + "mocha": "^6.2.2", "moment-timezone": "^0.5.31", "mongoose": "^5.9.4", "mongoose-autopopulate": "^0.12.0", "mongoose-delete": "^0.5.1", "mongoose-timestamp": "^0.6.0", "mongoose-ttl": "0.0.3", + "node-cache": "^5.1.2", "p-each-series": "^2.1.0", "path": "^0.12.7", "request": "^2.88.2", "require-all": "^3.0.0", "uuid": "^8.3.0", - "xml-js": "^1.6.11", - "chai": "^4.2.0", - "chai-http": "^4.3.0", - "mocha": "^6.2.2" + "xml-js": "^1.6.11" }, "devDependencies": { "grunt-apidoc": "^0.11.0", From 881ca49cf2c97884c4eef4bbdfd34d4c8c15f6a1 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Wed, 16 Mar 2022 12:01:57 +0530 Subject: [PATCH 02/15] eG changes --- models/projects.js | 2 +- module/reports/helper.js | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/models/projects.js b/models/projects.js index 597b8d2d..80cd51a1 100644 --- a/models/projects.js +++ b/models/projects.js @@ -83,7 +83,7 @@ module.exports = { default : [] }, entityId : { - type : "ObjectId", + type : String, index : true }, programId : { diff --git a/module/reports/helper.js b/module/reports/helper.js index e49a5793..aedd3109 100644 --- a/module/reports/helper.js +++ b/module/reports/helper.js @@ -39,12 +39,19 @@ module.exports = class ReportsHelper { try { let query = { }; + //eG code if (entityId) { - query["entityId"] = ObjectId(entityId); + query["entityId"] = entityId; } else { query["userId"] = userId } + // if (entityId) { + // query["entityId"] = ObjectId(entityId); + // } else { + // query["userId"] = userId + // } + let dateRange = await _getDateRangeofReport(reportType); let endOf = dateRange.endOf; let startFrom = dateRange.startFrom; @@ -64,14 +71,14 @@ module.exports = class ReportsHelper { { "syncedAt": { $gte: new Date(startFrom), $lte: new Date(endOf) } }, { "tasks": { $elemMatch: { isDeleted: { $ne: true },syncedAt: { $gte: new Date(startFrom), $lte: new Date(endOf) } } } }, ] - + console.log("Query : ",query) const projectDetails = await projectQueries.projectDocument( query, ["programId","programInformation.name", "entityInformation.name", "taskReport", "status", "tasks", "categories"], [] ); - + console.log("projectDetails : ",projectDetails) let tasksReport = { "total": 0, "overdue": 0 @@ -318,7 +325,9 @@ module.exports = class ReportsHelper { } } catch (error) { + console.log("error : ",error) return resolve({ + success: false, message: error.message, data: false @@ -352,9 +361,9 @@ module.exports = class ReportsHelper { $exists : true } }; - - if(entityId != "" && UTILS.isValidMongoId(entityId)) { - query.entityId = ObjectId(entityId); + + if( entityId != "" ) { + query.entityId = entityId; } if (userRole != "") { @@ -484,11 +493,17 @@ module.exports = class ReportsHelper { }; if (entityId) { - query["entityId"] = ObjectId(entityId); + query["entityId"] = entityId; } else { query["userId"] = userId } + // if (entityId) { + // query["entityId"] = ObjectId(entityId); + // } else { + // query["userId"] = userId + // } + let chartObject = []; let dateRange = await _getDateRangeofReport(reportType); let endOf = dateRange.endOf; From 254e497602a055a6c95db782fd0ec3cb606e3a38 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Mon, 21 Mar 2022 09:54:13 +0530 Subject: [PATCH 03/15] eG monday 22 --- generics/constants/common.js | 5 +- generics/constants/endpoints.js | 3 +- module/userProjects/helper.js | 239 +++++++++++++++++++++++++++++--- 3 files changed, 227 insertions(+), 20 deletions(-) diff --git a/generics/constants/common.js b/generics/constants/common.js index 009bf7e9..8b72cbe7 100644 --- a/generics/constants/common.js +++ b/generics/constants/common.js @@ -44,5 +44,8 @@ module.exports = { "CHILDREN" : "children", "ATTACHMENT_TYPE_LINK" : "link", "PROJECT_ATTACHMENT" : "project", - "TASK_ATTACHMENT" : "task" + "TASK_ATTACHMENT" : "task", + "SUNBIRD_SERVER_TIMEOUT" : 5000, + "TIMEOUT_ERROR" : "Server timeout error", + "OK" : "OK" }; diff --git a/generics/constants/endpoints.js b/generics/constants/endpoints.js index 4a249318..11e6ea9c 100644 --- a/generics/constants/endpoints.js +++ b/generics/constants/endpoints.js @@ -44,5 +44,6 @@ module.exports = { LIST_ENTITIES_BY_LOCATION_IDS : "/v1/entities/listByLocationIds", CREATE_IMPROVEMENT_PROJECT_SOLUTION : "/v1/solutions/create", PROJECT_AND_TASK_REPORT : "/v1/improvement-project/projectAndTaskReport", - FILES_DOWNLOADABLE_URL: "/v1/cloud-services/files/getDownloadableUrl" + FILES_DOWNLOADABLE_URL: "/v1/cloud-services/files/getDownloadableUrl", + GET_LOCATION_DATA : "/api/data/v1/location/search" }; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index c2856794..6b1779df 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -21,6 +21,7 @@ const projectTemplateTaskQueries = require(DB_QUERY_BASE_PATH + "/projectTemplat const kafkaProducersHelper = require(GENERICS_FILES_PATH + "/kafka/producers"); const removeFieldsFromRequest = ["submissionDetails"]; const programsQueries = require(DB_QUERY_BASE_PATH + "/programs"); +const sunbirdService = require(GENERICS_FILES_PATH + '/services/sunbird'); /** * UserProjectsHelper @@ -176,7 +177,7 @@ module.exports = class UserProjectsHelper { let addOrUpdateEntityToProject = false; if (data.entityId) { - + console.log("#####here") // If entity is not present in project or new entity is updated. if ( !userProject[0].entityInformation || @@ -188,7 +189,7 @@ module.exports = class UserProjectsHelper { addOrUpdateEntityToProject = true; } } - + console.log(" addOrUpdateEntityToProject : ", addOrUpdateEntityToProject) if (addOrUpdateEntityToProject) { let entityInformation = @@ -201,7 +202,7 @@ module.exports = class UserProjectsHelper { updateProject["entityInformation"] = entityInformation.data[0]; updateProject.entityId = entityInformation.data[0]._id; } - + console.log("updateProject.entityId : ",updateProject.entityId ) if (createNewProgramAndSolution || solutionExists) { let programAndSolutionInformation = @@ -912,7 +913,7 @@ module.exports = class UserProjectsHelper { "projectTemplateId" ] ); - + console.log("project details : ",project) if (!project.length > 0) { throw { status: HTTP_STATUS_CODE['bad_request'].status, @@ -1349,7 +1350,6 @@ module.exports = class UserProjectsHelper { static add(data, userId, userToken, appName = "", appVersion = "") { return new Promise(async (resolve, reject) => { try { - const projectsModel = Object.keys(schemas["projects"].schema); let createProject = {}; @@ -1395,7 +1395,7 @@ module.exports = class UserProjectsHelper { } createProject = _.merge(createProject, programAndSolutionInformation.data); - } else { + } else{ let queryData = {}; queryData["_id"] = data.programId; let programDetails = await programsQueries.programsDocument(queryData, @@ -1504,6 +1504,160 @@ module.exports = class UserProjectsHelper { } }); + // const projectsModel = Object.keys(schemas["projects"].schema); + // let createProject = {}; + + // createProject["userId"] = createProject["createdBy"] = createProject["updatedBy"] = userId; + + // let projectData = await _projectData(data); + // if (projectData && projectData.success == true) { + // createProject = _.merge(createProject, projectData.data); + // } + + // let createNewProgramAndSolution = false; + + // if (data.programId && data.programId !== "") { + // createNewProgramAndSolution = false; + // } + // else if (data.programName) { + // createNewProgramAndSolution = true; + // } + + // if (data.entityId) { + // let entityInformation = + // await _entitiesInformation([data.entityId]); + + // if (!entityInformation.success) { + // return resolve(entityInformation); + // } + + // createProject["entityInformation"] = entityInformation.data[0]; + // createProject.entityId = entityInformation.data[0]._id; + // } + // if (createNewProgramAndSolution) { + + // let programAndSolutionInformation = + // await this.createProgramAndSolution( + // data.programId, + // data.programName, + // createProject.entityId ? [createProject.entityId] : "", + // userToken + // ); + + // if (!programAndSolutionInformation.success) { + // return resolve(programAndSolutionInformation); + // } + // createProject = + // _.merge(createProject, programAndSolutionInformation.data); + // } else { + // let queryData = {}; + // queryData["_id"] = data.programId; + // let programDetails = await programsQueries.programsDocument(queryData, + // [ + // "_id", + // "name", + // "description", + // "isAPrivateProgram" + // ] + // ); + // if( !programDetails.length > 0 ){ + // throw { + // status: HTTP_STATUS_CODE['bad_request'].status, + // message: CONSTANTS.apiResponses.PROGRAM_NOT_FOUND + // }; + // } + // let programInformationData = {}; + // programInformationData["programInformation"] = programDetails[0]; + // createProject = + // _.merge(createProject, programInformationData); + // } + + // if (data.tasks) { + + // let taskReport = {}; + + // createProject.tasks = await _projectTask( + // data.tasks + // ); + + // taskReport.total = createProject.tasks.length; + + // createProject.tasks.forEach(task => { + // if (!taskReport[task.status]) { + // taskReport[task.status] = 1; + // } else { + // taskReport[task.status] += 1; + // } + // }); + + // createProject["taskReport"] = taskReport; + // } + + // let booleanData = this.booleanData(schemas["projects"].schema); + // let mongooseIdData = this.mongooseIdData(schemas["projects"].schema); + + + // Object.keys(data).forEach(updateData => { + // if ( + // !createProject[updateData] && + // projectsModel.includes(updateData) + // ) { + + // if (booleanData.includes(updateData)) { + + // createProject[updateData] = + // UTILS.convertStringToBoolean(data[updateData]); + + // } else if (mongooseIdData.includes(updateData)) { + // createProject[updateData] = ObjectId(data[updateData]); + // } else { + // createProject[updateData] = data[updateData]; + // } + // } + // }); + + // createProject["appInformation"] = {}; + // if (appName !== "") { + // createProject["appInformation"]["appName"] = appName; + // } + + // if (appVersion !== "") { + // createProject["appInformation"]["appVersion"] = appVersion; + // } + + // createProject["lastDownloadedAt"] = new Date(); + + // if (data.profileInformation) { + // createProject.userRoleInformation = data.profileInformation; + // } + + // createProject.status = UTILS.convertProjectStatus(data.status); + // let userProject = await projectQueries.createProject( + // createProject + // ); + + // await kafkaProducersHelper.pushProjectToKafka(userProject); + + // if (!userProject._id) { + // throw { + // message: CONSTANTS.apiResponses.USER_PROJECT_NOT_CREATED, + // status: HTTP_STATUS_CODE['bad_request'].status + // } + // } + + // return resolve({ + // success: true, + // message: CONSTANTS.apiResponses.PROJECT_CREATED, + // data: { + // programId: + // userProject.programInformation && userProject.programInformation._id ? + // userProject.programInformation._id : data.programId, + // projectId: userProject._id, + // lastDownloadedAt: userProject.lastDownloadedAt, + // hasAcceptedTAndC : userProject.hasAcceptedTAndC ? userProject.hasAcceptedTAndC : false + // } + // }); + } catch (error) { return resolve({ status: @@ -2479,25 +2633,42 @@ function _projectCategories(categories) { function _entitiesInformation(entityIds) { return new Promise(async (resolve, reject) => { try { - - let entityData = - await coreService.entityDocuments( - entityIds, - ["metaInformation", "entityType", "entityTypeId", "registryDetails"] - ); - - if (!entityData.success) { + let bodyData={}; + bodyData["request"] = {}; + bodyData["request"]["filters"] = {}; + bodyData["request"]["filters"]["id"] = entityIds; + console.log(" bodyData inside recursive fn : ", bodyData["request"]["filters"]) + let entityDetails = await sunbirdService.learnerLocationSearch(bodyData); + console.log("entityDetails:",entityDetails) + let entities = entityDetails.data.response; + + if (!entities.length > 0) { throw { status: HTTP_STATUS_CODE['bad_request'].status, message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND } } + let entityResult = []; + //formating response + entities.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); + }); + console.log("entityResult : ",entityResult) let entitiesData = []; - if (entityData.success && entityData.data.length > 0) { + if ( entities.length > 0 ) { - entitiesData = _entitiesMetaInformation(entityData.data); + entitiesData = _entitiesMetaInformation(entityResult); } return resolve({ @@ -2505,6 +2676,31 @@ function _entitiesInformation(entityIds) { data: entitiesData }); + // let entityData = + // await coreService.entityDocuments( + // entityIds, + // ["metaInformation", "entityType", "entityTypeId", "registryDetails"] + // ); + + // if (!entityData.success) { + // throw { + // status: HTTP_STATUS_CODE['bad_request'].status, + // message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND + // } + // } + // console.log("entity data before: ",entityData) + // let entitiesData = []; + + // if (entityData.success && entityData.data.length > 0) { + + // entitiesData = _entitiesMetaInformation(entityData.data); + // } + + // return resolve({ + // success: true, + // data: entitiesData + // }); + } catch (error) { return resolve({ status: @@ -2768,13 +2964,20 @@ function _observationDetails(observationData, userRoleAndProfileInformation = {} function _entitiesMetaInformation(entitiesData) { entitiesData = entitiesData.map(entity => { - entity.metaInformation._id = ObjectId(entity._id); + entity.metaInformation._id = entity._id; entity.metaInformation.entityType = entity.entityType; - entity.metaInformation.entityTypeId = ObjectId(entity.entityTypeId); entity.metaInformation.registryDetails = entity.registryDetails; return entity.metaInformation; }); + // entitiesData = entitiesData.map(entity => { + // entity.metaInformation._id = ObjectId(entity._id); + // entity.metaInformation.entityType = entity.entityType; + // entity.metaInformation.entityTypeId = ObjectId(entity.entityTypeId); + // entity.metaInformation.registryDetails = entity.registryDetails; + // return entity.metaInformation; + // }); + console.log("entitiesData : ",entitiesData) return entitiesData; } From d5e8dfccda3a3be7b0074a1e6a0ac03d2975f2bd Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Mon, 21 Mar 2022 09:59:38 +0530 Subject: [PATCH 04/15] sunbird service --- generics/services/sunbird.js | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 generics/services/sunbird.js diff --git a/generics/services/sunbird.js b/generics/services/sunbird.js new file mode 100644 index 00000000..d69ec39f --- /dev/null +++ b/generics/services/sunbird.js @@ -0,0 +1,73 @@ +/** + * name : sunbird.js + * author : Vishnudas + * Date : 16-March-2022 + * Description : All Sunbird learner related api call. + */ + +//dependencies + + +const request = require('request'); +const sunbirdBaseUrl = process.env.SUNBIRD_SERVICE_URL; + +/** + * + * @function + * @name learnerLocationSearch + * @param {String} bearerToken - autherization token. + * @param {object} bodyData - bodydata . + * @returns {Promise} returns a promise. +*/ + +const learnerLocationSearch = function ( bodyData ) { + return new Promise(async (resolve, reject) => { + try { + + const url = + sunbirdBaseUrl + CONSTANTS.endpoints.GET_LOCATION_DATA; + const options = { + headers : { + "Authorization" : process.env.SUNBIRD_SERVICE_AUTHERIZATION, + "content-type": "application/json" + }, + json : bodyData + }; + + request.post(url,options,kendraCallback); + + function kendraCallback(err, data) { + + let result = { + success : true + }; + + if (err) { + result.success = false; + } else { + + let response = data.body; + + if( response.responseCode === CONSTANTS.common.OK) { + result["data"] = response.result; + } else { + result.success = false; + } + } + return resolve(result); + } + + setTimeout(function () { + return reject (CONSTANTS.common.TIMEOUT_ERROR) + }, CONSTANTS.common.SUNBIRD_SERVER_TIMEOUT); + + + } catch (error) { + return reject(error); + } + }) +} + +module.exports = { + learnerLocationSearch : learnerLocationSearch +}; \ No newline at end of file From 255003ef1163b8c69dd797e77f378eea444dff48 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Tue, 22 Mar 2022 22:21:08 +0530 Subject: [PATCH 05/15] entity generalization code march 22 2022 --- generics/services/sunbird.js | 7 +- module/reports/helper.js | 18 +-- module/userProjects/helper.js | 212 ++-------------------------------- 3 files changed, 20 insertions(+), 217 deletions(-) diff --git a/generics/services/sunbird.js b/generics/services/sunbird.js index d69ec39f..4006a779 100644 --- a/generics/services/sunbird.js +++ b/generics/services/sunbird.js @@ -16,14 +16,17 @@ const sunbirdBaseUrl = process.env.SUNBIRD_SERVICE_URL; * @function * @name learnerLocationSearch * @param {String} bearerToken - autherization token. - * @param {object} bodyData - bodydata . + * @param {object} filterData - bodydata . * @returns {Promise} returns a promise. */ -const learnerLocationSearch = function ( bodyData ) { +const learnerLocationSearch = function ( filterData ) { return new Promise(async (resolve, reject) => { try { + let bodyData={}; + bodyData["request"] = {}; + bodyData["request"]["filters"] = filterData; const url = sunbirdBaseUrl + CONSTANTS.endpoints.GET_LOCATION_DATA; const options = { diff --git a/module/reports/helper.js b/module/reports/helper.js index aedd3109..5a800d60 100644 --- a/module/reports/helper.js +++ b/module/reports/helper.js @@ -39,18 +39,13 @@ module.exports = class ReportsHelper { try { let query = { }; - //eG code + if (entityId) { query["entityId"] = entityId; } else { query["userId"] = userId } - // if (entityId) { - // query["entityId"] = ObjectId(entityId); - // } else { - // query["userId"] = userId - // } let dateRange = await _getDateRangeofReport(reportType); let endOf = dateRange.endOf; @@ -71,14 +66,14 @@ module.exports = class ReportsHelper { { "syncedAt": { $gte: new Date(startFrom), $lte: new Date(endOf) } }, { "tasks": { $elemMatch: { isDeleted: { $ne: true },syncedAt: { $gte: new Date(startFrom), $lte: new Date(endOf) } } } }, ] - console.log("Query : ",query) + const projectDetails = await projectQueries.projectDocument( query, ["programId","programInformation.name", "entityInformation.name", "taskReport", "status", "tasks", "categories"], [] ); - console.log("projectDetails : ",projectDetails) + let tasksReport = { "total": 0, "overdue": 0 @@ -498,12 +493,7 @@ module.exports = class ReportsHelper { query["userId"] = userId } - // if (entityId) { - // query["entityId"] = ObjectId(entityId); - // } else { - // query["userId"] = userId - // } - + let chartObject = []; let dateRange = await _getDateRangeofReport(reportType); let endOf = dateRange.endOf; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 6b1779df..c00152cb 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -177,7 +177,7 @@ module.exports = class UserProjectsHelper { let addOrUpdateEntityToProject = false; if (data.entityId) { - console.log("#####here") + // If entity is not present in project or new entity is updated. if ( !userProject[0].entityInformation || @@ -189,7 +189,7 @@ module.exports = class UserProjectsHelper { addOrUpdateEntityToProject = true; } } - console.log(" addOrUpdateEntityToProject : ", addOrUpdateEntityToProject) + if (addOrUpdateEntityToProject) { let entityInformation = @@ -202,7 +202,7 @@ module.exports = class UserProjectsHelper { updateProject["entityInformation"] = entityInformation.data[0]; updateProject.entityId = entityInformation.data[0]._id; } - console.log("updateProject.entityId : ",updateProject.entityId ) + if (createNewProgramAndSolution || solutionExists) { let programAndSolutionInformation = @@ -913,7 +913,6 @@ module.exports = class UserProjectsHelper { "projectTemplateId" ] ); - console.log("project details : ",project) if (!project.length > 0) { throw { status: HTTP_STATUS_CODE['bad_request'].status, @@ -1503,161 +1502,6 @@ module.exports = class UserProjectsHelper { hasAcceptedTAndC : userProject.hasAcceptedTAndC ? userProject.hasAcceptedTAndC : false } }); - - // const projectsModel = Object.keys(schemas["projects"].schema); - // let createProject = {}; - - // createProject["userId"] = createProject["createdBy"] = createProject["updatedBy"] = userId; - - // let projectData = await _projectData(data); - // if (projectData && projectData.success == true) { - // createProject = _.merge(createProject, projectData.data); - // } - - // let createNewProgramAndSolution = false; - - // if (data.programId && data.programId !== "") { - // createNewProgramAndSolution = false; - // } - // else if (data.programName) { - // createNewProgramAndSolution = true; - // } - - // if (data.entityId) { - // let entityInformation = - // await _entitiesInformation([data.entityId]); - - // if (!entityInformation.success) { - // return resolve(entityInformation); - // } - - // createProject["entityInformation"] = entityInformation.data[0]; - // createProject.entityId = entityInformation.data[0]._id; - // } - // if (createNewProgramAndSolution) { - - // let programAndSolutionInformation = - // await this.createProgramAndSolution( - // data.programId, - // data.programName, - // createProject.entityId ? [createProject.entityId] : "", - // userToken - // ); - - // if (!programAndSolutionInformation.success) { - // return resolve(programAndSolutionInformation); - // } - // createProject = - // _.merge(createProject, programAndSolutionInformation.data); - // } else { - // let queryData = {}; - // queryData["_id"] = data.programId; - // let programDetails = await programsQueries.programsDocument(queryData, - // [ - // "_id", - // "name", - // "description", - // "isAPrivateProgram" - // ] - // ); - // if( !programDetails.length > 0 ){ - // throw { - // status: HTTP_STATUS_CODE['bad_request'].status, - // message: CONSTANTS.apiResponses.PROGRAM_NOT_FOUND - // }; - // } - // let programInformationData = {}; - // programInformationData["programInformation"] = programDetails[0]; - // createProject = - // _.merge(createProject, programInformationData); - // } - - // if (data.tasks) { - - // let taskReport = {}; - - // createProject.tasks = await _projectTask( - // data.tasks - // ); - - // taskReport.total = createProject.tasks.length; - - // createProject.tasks.forEach(task => { - // if (!taskReport[task.status]) { - // taskReport[task.status] = 1; - // } else { - // taskReport[task.status] += 1; - // } - // }); - - // createProject["taskReport"] = taskReport; - // } - - // let booleanData = this.booleanData(schemas["projects"].schema); - // let mongooseIdData = this.mongooseIdData(schemas["projects"].schema); - - - // Object.keys(data).forEach(updateData => { - // if ( - // !createProject[updateData] && - // projectsModel.includes(updateData) - // ) { - - // if (booleanData.includes(updateData)) { - - // createProject[updateData] = - // UTILS.convertStringToBoolean(data[updateData]); - - // } else if (mongooseIdData.includes(updateData)) { - // createProject[updateData] = ObjectId(data[updateData]); - // } else { - // createProject[updateData] = data[updateData]; - // } - // } - // }); - - // createProject["appInformation"] = {}; - // if (appName !== "") { - // createProject["appInformation"]["appName"] = appName; - // } - - // if (appVersion !== "") { - // createProject["appInformation"]["appVersion"] = appVersion; - // } - - // createProject["lastDownloadedAt"] = new Date(); - - // if (data.profileInformation) { - // createProject.userRoleInformation = data.profileInformation; - // } - - // createProject.status = UTILS.convertProjectStatus(data.status); - // let userProject = await projectQueries.createProject( - // createProject - // ); - - // await kafkaProducersHelper.pushProjectToKafka(userProject); - - // if (!userProject._id) { - // throw { - // message: CONSTANTS.apiResponses.USER_PROJECT_NOT_CREATED, - // status: HTTP_STATUS_CODE['bad_request'].status - // } - // } - - // return resolve({ - // success: true, - // message: CONSTANTS.apiResponses.PROJECT_CREATED, - // data: { - // programId: - // userProject.programInformation && userProject.programInformation._id ? - // userProject.programInformation._id : data.programId, - // projectId: userProject._id, - // lastDownloadedAt: userProject.lastDownloadedAt, - // hasAcceptedTAndC : userProject.hasAcceptedTAndC ? userProject.hasAcceptedTAndC : false - // } - // }); - } catch (error) { return resolve({ status: @@ -2633,13 +2477,13 @@ function _projectCategories(categories) { function _entitiesInformation(entityIds) { return new Promise(async (resolve, reject) => { try { - let bodyData={}; - bodyData["request"] = {}; - bodyData["request"]["filters"] = {}; - bodyData["request"]["filters"]["id"] = entityIds; - console.log(" bodyData inside recursive fn : ", bodyData["request"]["filters"]) + let bodyData={ + "id" : entityIds + }; + + let entityDetails = await sunbirdService.learnerLocationSearch(bodyData); - console.log("entityDetails:",entityDetails) + let entities = entityDetails.data.response; if (!entities.length > 0) { @@ -2662,7 +2506,7 @@ function _entitiesInformation(entityIds) { data.registryDetails.code = entityData.code; entityResult.push(data); }); - console.log("entityResult : ",entityResult) + let entitiesData = []; @@ -2676,31 +2520,6 @@ function _entitiesInformation(entityIds) { data: entitiesData }); - // let entityData = - // await coreService.entityDocuments( - // entityIds, - // ["metaInformation", "entityType", "entityTypeId", "registryDetails"] - // ); - - // if (!entityData.success) { - // throw { - // status: HTTP_STATUS_CODE['bad_request'].status, - // message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND - // } - // } - // console.log("entity data before: ",entityData) - // let entitiesData = []; - - // if (entityData.success && entityData.data.length > 0) { - - // entitiesData = _entitiesMetaInformation(entityData.data); - // } - - // return resolve({ - // success: true, - // data: entitiesData - // }); - } catch (error) { return resolve({ status: @@ -2968,16 +2787,7 @@ function _entitiesMetaInformation(entitiesData) { entity.metaInformation.entityType = entity.entityType; entity.metaInformation.registryDetails = entity.registryDetails; return entity.metaInformation; - }); - - // entitiesData = entitiesData.map(entity => { - // entity.metaInformation._id = ObjectId(entity._id); - // entity.metaInformation.entityType = entity.entityType; - // entity.metaInformation.entityTypeId = ObjectId(entity.entityTypeId); - // entity.metaInformation.registryDetails = entity.registryDetails; - // return entity.metaInformation; - // }); - console.log("entitiesData : ",entitiesData) + }); return entitiesData; } From 3607a15721f566e021da61592bae70d49e742075 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Wed, 23 Mar 2022 18:10:43 +0530 Subject: [PATCH 06/15] resolves lvl1 --- generics/constants/common.js | 1 - generics/services/sunbird.js | 16 +++++++++------- module/userProjects/helper.js | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/generics/constants/common.js b/generics/constants/common.js index 8b72cbe7..04d18daa 100644 --- a/generics/constants/common.js +++ b/generics/constants/common.js @@ -46,6 +46,5 @@ module.exports = { "PROJECT_ATTACHMENT" : "project", "TASK_ATTACHMENT" : "task", "SUNBIRD_SERVER_TIMEOUT" : 5000, - "TIMEOUT_ERROR" : "Server timeout error", "OK" : "OK" }; diff --git a/generics/services/sunbird.js b/generics/services/sunbird.js index 4006a779..3919f1fb 100644 --- a/generics/services/sunbird.js +++ b/generics/services/sunbird.js @@ -16,7 +16,7 @@ const sunbirdBaseUrl = process.env.SUNBIRD_SERVICE_URL; * @function * @name learnerLocationSearch * @param {String} bearerToken - autherization token. - * @param {object} filterData - bodydata . + * @param {object} bodyData - bodydata . * @returns {Promise} returns a promise. */ @@ -39,12 +39,13 @@ const learnerLocationSearch = function ( filterData ) { request.post(url,options,kendraCallback); - function kendraCallback(err, data) { + let result = { + success : true + }; - let result = { - success : true - }; + function kendraCallback(err, data) { + if (err) { result.success = false; } else { @@ -61,10 +62,11 @@ const learnerLocationSearch = function ( filterData ) { } setTimeout(function () { - return reject (CONSTANTS.common.TIMEOUT_ERROR) + return reject (result = { + success : false + }); }, CONSTANTS.common.SUNBIRD_SERVER_TIMEOUT); - } catch (error) { return reject(error); } diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index c00152cb..aa77d44a 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -2483,15 +2483,15 @@ function _entitiesInformation(entityIds) { let entityDetails = await sunbirdService.learnerLocationSearch(bodyData); - - let entities = entityDetails.data.response; - if (!entities.length > 0) { + if (!entityDetails.success || !entityDetails.data.response.length > 0) { throw { status: HTTP_STATUS_CODE['bad_request'].status, message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND } } + + let entities = entityDetails.data.response; let entityResult = []; //formating response entities.map(entityData => { From f8938378ad4fe092102f488ea819c35d0eb9eb27 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Tue, 29 Mar 2022 09:48:30 +0530 Subject: [PATCH 07/15] edit in sunbirdservice --- generics/services/sunbird.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generics/services/sunbird.js b/generics/services/sunbird.js index 3919f1fb..acb324cf 100644 --- a/generics/services/sunbird.js +++ b/generics/services/sunbird.js @@ -37,13 +37,13 @@ const learnerLocationSearch = function ( filterData ) { json : bodyData }; - request.post(url,options,kendraCallback); + request.post(url,options,learnerSearchCallback); let result = { success : true }; - function kendraCallback(err, data) { + function learnerSearchCallback(err, data) { if (err) { From 30e7001753dee0073405386e34afaa8ccca985a1 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Wed, 30 Mar 2022 16:30:54 +0530 Subject: [PATCH 08/15] env and data check added --- envVariables.js | 4 ++++ generics/constants/common.js | 1 - generics/services/sunbird.js | 4 ++-- module/userProjects/helper.js | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/envVariables.js b/envVariables.js index a1600dab..f3f893f5 100644 --- a/envVariables.js +++ b/envVariables.js @@ -35,6 +35,10 @@ let enviromentVariables = { "KAFKA_URL" : { "message" : "Required", "optional" : false + }, + "SUNBIRD_SERVICE_URL" : { + "message" : "Required sunbird service url", + "optional" : false } } diff --git a/generics/constants/common.js b/generics/constants/common.js index 04d18daa..23a7f786 100644 --- a/generics/constants/common.js +++ b/generics/constants/common.js @@ -45,6 +45,5 @@ module.exports = { "ATTACHMENT_TYPE_LINK" : "link", "PROJECT_ATTACHMENT" : "project", "TASK_ATTACHMENT" : "task", - "SUNBIRD_SERVER_TIMEOUT" : 5000, "OK" : "OK" }; diff --git a/generics/services/sunbird.js b/generics/services/sunbird.js index acb324cf..4ca73220 100644 --- a/generics/services/sunbird.js +++ b/generics/services/sunbird.js @@ -10,7 +10,7 @@ const request = require('request'); const sunbirdBaseUrl = process.env.SUNBIRD_SERVICE_URL; - +const serverTimeout = process.env.SUNBIRD_SERVER_TIMEOUT ? parseInt( process.env.SUNBIRD_SERVER_TIMEOUT ) : 5000; /** * * @function @@ -65,7 +65,7 @@ const learnerLocationSearch = function ( filterData ) { return reject (result = { success : false }); - }, CONSTANTS.common.SUNBIRD_SERVER_TIMEOUT); + }, serverTimeout); } catch (error) { return reject(error); diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index aa77d44a..2a3170b7 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -2484,7 +2484,7 @@ function _entitiesInformation(entityIds) { let entityDetails = await sunbirdService.learnerLocationSearch(bodyData); - if (!entityDetails.success || !entityDetails.data.response.length > 0) { + if (!entityDetails.success || !entityDetails.data || !entityDetails.data.response.length > 0) { throw { status: HTTP_STATUS_CODE['bad_request'].status, message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND From 70cb2f330e46cd70a611e59afef5a2ffae914a28 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Fri, 22 Jul 2022 13:17:36 +0530 Subject: [PATCH 09/15] resolves_users.js added --- .env.sample | 5 ++++- envVariables.js | 4 ++-- generics/constants/endpoints.js | 2 +- generics/services/{sunbird.js => users.js} | 20 ++++++++------------ module/userProjects/helper.js | 6 +++--- 5 files changed, 18 insertions(+), 19 deletions(-) rename generics/services/{sunbird.js => users.js} (79%) diff --git a/.env.sample b/.env.sample index 81fa286c..f6307ace 100644 --- a/.env.sample +++ b/.env.sample @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/envVariables.js b/envVariables.js index f3f893f5..9ccd9f9f 100644 --- a/envVariables.js +++ b/envVariables.js @@ -36,8 +36,8 @@ let enviromentVariables = { "message" : "Required", "optional" : false }, - "SUNBIRD_SERVICE_URL" : { - "message" : "Required sunbird service url", + "USER_SERVICE_URL" : { + "message" : "Required user service base url", "optional" : false } } diff --git a/generics/constants/endpoints.js b/generics/constants/endpoints.js index 11e6ea9c..a627540b 100644 --- a/generics/constants/endpoints.js +++ b/generics/constants/endpoints.js @@ -45,5 +45,5 @@ module.exports = { CREATE_IMPROVEMENT_PROJECT_SOLUTION : "/v1/solutions/create", PROJECT_AND_TASK_REPORT : "/v1/improvement-project/projectAndTaskReport", FILES_DOWNLOADABLE_URL: "/v1/cloud-services/files/getDownloadableUrl", - GET_LOCATION_DATA : "/api/data/v1/location/search" + GET_LOCATION_DATA : "/v1/location/search" }; diff --git a/generics/services/sunbird.js b/generics/services/users.js similarity index 79% rename from generics/services/sunbird.js rename to generics/services/users.js index 4ca73220..c407420a 100644 --- a/generics/services/sunbird.js +++ b/generics/services/users.js @@ -1,15 +1,13 @@ /** - * name : sunbird.js - * author : Vishnudas - * Date : 16-March-2022 - * Description : All Sunbird learner related api call. + * name : users.js + * author : Vishnu + * Date : 07-April-2022 + * Description : All users related api call. */ //dependencies - - const request = require('request'); -const sunbirdBaseUrl = process.env.SUNBIRD_SERVICE_URL; +const userServiceUrl = process.env.USER_SERVICE_URL; const serverTimeout = process.env.SUNBIRD_SERVER_TIMEOUT ? parseInt( process.env.SUNBIRD_SERVER_TIMEOUT ) : 5000; /** * @@ -28,10 +26,9 @@ const learnerLocationSearch = function ( filterData ) { bodyData["request"] = {}; bodyData["request"]["filters"] = filterData; const url = - sunbirdBaseUrl + CONSTANTS.endpoints.GET_LOCATION_DATA; + userServiceUrl + CONSTANTS.endpoints.GET_LOCATION_DATA; const options = { headers : { - "Authorization" : process.env.SUNBIRD_SERVICE_AUTHERIZATION, "content-type": "application/json" }, json : bodyData @@ -62,7 +59,7 @@ const learnerLocationSearch = function ( filterData ) { } setTimeout(function () { - return reject (result = { + return resolve (result = { success : false }); }, serverTimeout); @@ -72,7 +69,6 @@ const learnerLocationSearch = function ( filterData ) { } }) } - module.exports = { - learnerLocationSearch : learnerLocationSearch + learnerLocationSearch : learnerLocationSearch }; \ No newline at end of file diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 2a3170b7..865ded02 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -21,7 +21,7 @@ const projectTemplateTaskQueries = require(DB_QUERY_BASE_PATH + "/projectTemplat const kafkaProducersHelper = require(GENERICS_FILES_PATH + "/kafka/producers"); const removeFieldsFromRequest = ["submissionDetails"]; const programsQueries = require(DB_QUERY_BASE_PATH + "/programs"); -const sunbirdService = require(GENERICS_FILES_PATH + '/services/sunbird'); +const sunbirdUserProfile = require(GENERICS_FILES_PATH + "/services/users"); /** * UserProjectsHelper @@ -2482,9 +2482,9 @@ function _entitiesInformation(entityIds) { }; - let entityDetails = await sunbirdService.learnerLocationSearch(bodyData); + let entityDetails = await sunbirdUserProfile.learnerLocationSearch(bodyData); - if (!entityDetails.success || !entityDetails.data || !entityDetails.data.response.length > 0) { + if (!entityDetails.success || !entityDetails.data || !entityDetails.data.response || !entityDetails.data.response.length > 0) { throw { status: HTTP_STATUS_CODE['bad_request'].status, message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND From 420b0aff856bba01e4fc58dc7cccdcff49879ddf Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Fri, 22 Jul 2022 13:22:01 +0530 Subject: [PATCH 10/15] resolve --- module/userProjects/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 865ded02..949ff975 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1394,7 +1394,7 @@ module.exports = class UserProjectsHelper { } createProject = _.merge(createProject, programAndSolutionInformation.data); - } else{ + } else { let queryData = {}; queryData["_id"] = data.programId; let programDetails = await programsQueries.programsDocument(queryData, @@ -2510,7 +2510,7 @@ function _entitiesInformation(entityIds) { let entitiesData = []; - if ( entities.length > 0 ) { + if ( entityResult.length > 0 ) { entitiesData = _entitiesMetaInformation(entityResult); } From dc13f13e887fd5457ff87c18211b7e1fd02eb24e Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Thu, 4 Aug 2022 11:55:25 +0530 Subject: [PATCH 11/15] logic to check for locationCode added --- generics/helpers/utils.js | 33 ++++++++++++++++++++++--- module/userProjects/helper.js | 46 ++++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/generics/helpers/utils.js b/generics/helpers/utils.js index 295cb104..cf7086ff 100644 --- a/generics/helpers/utils.js +++ b/generics/helpers/utils.js @@ -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 @@ -233,6 +234,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, @@ -245,5 +269,6 @@ module.exports = { isValidMongoId : isValidMongoId, convertProjectStatus : convertProjectStatus, revertProjectStatus:revertProjectStatus, - revertStatusorNot:revertStatusorNot + revertStatusorNot:revertStatusorNot, + checkValidUUID : checkValidUUID }; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 949ff975..842572ff 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -2477,24 +2477,47 @@ function _projectCategories(categories) { function _entitiesInformation(entityIds) { return new Promise(async (resolve, reject) => { try { - let bodyData={ - "id" : entityIds - }; - - - let entityDetails = await sunbirdUserProfile.learnerLocationSearch(bodyData); + let locationIds = []; + let locationCodes = []; + let entityInformations = []; + entityIds.forEach(entity=>{ + if (UTILS.checkValidUUID(entity)) { + locationIds.push(entity); + } else { + locationCodes.push(entity); + } + }); + + if ( locationIds.length > 0 ) { + let bodyData = { + "id" : locationIds + } + let entityData = await sunbirdUserProfile.learnerLocationSearch( bodyData ); + if ( entityData.success && entityData.data && entityData.data.response && entityData.data.response.length > 0 ) { + entityInformations = entityData.data.response; + } + } - if (!entityDetails.success || !entityDetails.data || !entityDetails.data.response || !entityDetails.data.response.length > 0) { + if ( locationCodes.length > 0 ) { + let bodyData = { + "code" : locationCodes + } + let entityData = await sunbirdUserProfile.learnerLocationSearch( bodyData ); + if ( entityData.success && entityData.data && entityData.data.response && entityData.data.response.length > 0 ) { + entityInformations = entityInformations.concat(entityData.data.response); + } + } + + if ( !entityInformations.length > 0 ) { throw { status: HTTP_STATUS_CODE['bad_request'].status, message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND } } - - let entities = entityDetails.data.response; + let entityResult = []; //formating response - entities.map(entityData => { + entityInformations.map(entityData => { let data = {}; data._id = entityData.id; data.entityType = entityData.type; @@ -2514,7 +2537,7 @@ function _entitiesInformation(entityIds) { entitiesData = _entitiesMetaInformation(entityResult); } - + return resolve({ success: true, data: entitiesData @@ -2781,7 +2804,6 @@ function _observationDetails(observationData, userRoleAndProfileInformation = {} */ function _entitiesMetaInformation(entitiesData) { - entitiesData = entitiesData.map(entity => { entity.metaInformation._id = entity._id; entity.metaInformation.entityType = entity.entityType; From b0e92fbcb7d3575fbdf772bad43bf5a4ae506429 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Tue, 9 Aug 2022 09:26:00 +0530 Subject: [PATCH 12/15] user service variable change --- module/userProjects/helper.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index e6afa012..c1fc08bf 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -23,7 +23,6 @@ const removeFieldsFromRequest = ["submissionDetails"]; const programsQueries = require(DB_QUERY_BASE_PATH + "/programs"); const userProfileService = require(GENERICS_FILES_PATH + "/services/users"); const solutionsHelper = require(MODULES_BASE_PATH + "/solutions/helper"); -const sunbirdUserProfile = require(GENERICS_FILES_PATH + "/services/users"); /** * UserProjectsHelper @@ -2693,7 +2692,7 @@ function _entitiesInformation(entityIds) { let bodyData = { "id" : locationIds } - let entityData = await sunbirdUserProfile.learnerLocationSearch( bodyData ); + let entityData = await userProfileService.learnerLocationSearch( bodyData ); if ( entityData.success && entityData.data && entityData.data.response && entityData.data.response.length > 0 ) { entityInformations = entityData.data.response; } @@ -2703,7 +2702,7 @@ function _entitiesInformation(entityIds) { let bodyData = { "code" : locationCodes } - let entityData = await sunbirdUserProfile.learnerLocationSearch( bodyData ); + let entityData = await userProfileService.learnerLocationSearch( bodyData ); if ( entityData.success && entityData.data && entityData.data.response && entityData.data.response.length > 0 ) { entityInformations = entityInformations.concat(entityData.data.response); } From 53f440010f50d1e77764ac5dcd360cefcb30b677 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Tue, 16 Aug 2022 14:51:43 +0530 Subject: [PATCH 13/15] review changes --- generics/services/users.js | 30 ++++++++++++++++-------------- module/userProjects/helper.js | 12 ++++++------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/generics/services/users.js b/generics/services/users.js index 8f325213..23057c0f 100644 --- a/generics/services/users.js +++ b/generics/services/users.js @@ -8,6 +8,7 @@ //dependencies const request = require('request'); const userServiceUrl = process.env.USER_SERVICE_URL; +const serverTimeout = CONSTANTS.common.SERVER_TIME_OUT; const profile = function ( token,userId = "" ) { return new Promise(async (resolve, reject) => { @@ -59,17 +60,16 @@ const profile = function ( token,userId = "" ) { }) } -const serverTimeout = process.env.SUNBIRD_SERVER_TIMEOUT ? parseInt( process.env.SUNBIRD_SERVER_TIMEOUT ) : 5000; + /** * * @function - * @name learnerLocationSearch - * @param {String} bearerToken - autherization token. + * @name locationSearch * @param {object} bodyData - bodydata . * @returns {Promise} returns a promise. */ -const learnerLocationSearch = function ( filterData ) { +const locationSearch = function ( filterData ) { return new Promise(async (resolve, reject) => { try { @@ -85,25 +85,27 @@ const learnerLocationSearch = function ( filterData ) { json : bodyData }; - request.post(url,options,learnerSearchCallback); + request.post(url,options,requestCallback); let result = { success : true }; - function learnerSearchCallback(err, data) { - - + function requestCallback(err, data) { if (err) { result.success = false; } else { - let response = data.body; - - if( response.responseCode === CONSTANTS.common.OK) { - result["data"] = response.result; + + if( response.responseCode === CONSTANTS.common.OK && + response.result && + response.result.response && + response.result.response.length > 0 + ) { + result["data"] = response.result.response; + result["count"] = response.result.count; } else { - result.success = false; + result.success = false; } } return resolve(result); @@ -122,5 +124,5 @@ const learnerLocationSearch = function ( filterData ) { } module.exports = { profile : profile, - learnerLocationSearch : learnerLocationSearch + locationSearch : locationSearch }; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index c1fc08bf..a481f135 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -2692,9 +2692,9 @@ function _entitiesInformation(entityIds) { let bodyData = { "id" : locationIds } - let entityData = await userProfileService.learnerLocationSearch( bodyData ); - if ( entityData.success && entityData.data && entityData.data.response && entityData.data.response.length > 0 ) { - entityInformations = entityData.data.response; + let entityData = await userProfileService.locationSearch( bodyData ); + if ( entityData.success ) { + entityInformations = entityData.data; } } @@ -2702,9 +2702,9 @@ function _entitiesInformation(entityIds) { let bodyData = { "code" : locationCodes } - let entityData = await userProfileService.learnerLocationSearch( bodyData ); - if ( entityData.success && entityData.data && entityData.data.response && entityData.data.response.length > 0 ) { - entityInformations = entityInformations.concat(entityData.data.response); + let entityData = await userProfileService.locationSearch( bodyData ); + if ( entityData.success ) { + entityInformations = entityInformations.concat(entityData.data); } } From 7478444fba8eaa3dd6a61cfcf6fea17a89cd47e9 Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Mon, 22 Aug 2022 18:18:19 +0530 Subject: [PATCH 14/15] service param change --- generics/services/users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generics/services/users.js b/generics/services/users.js index 23057c0f..c19e9273 100644 --- a/generics/services/users.js +++ b/generics/services/users.js @@ -65,7 +65,7 @@ const profile = function ( token,userId = "" ) { * * @function * @name locationSearch - * @param {object} bodyData - bodydata . + * @param {object} filterData - location search filter object. * @returns {Promise} returns a promise. */ From 0b2478c21942b468d3cb66945512426bde5f28ab Mon Sep 17 00:00:00 2001 From: VISHNUDAS-tunerlabse Date: Tue, 23 Aug 2022 06:54:20 +0530 Subject: [PATCH 15/15] review change --- generics/helpers/cache.js | 62 ----------------------------------- generics/services/users.js | 31 ++++++++++++++---- module/reports/helper.js | 1 - module/userProjects/helper.js | 29 +++------------- 4 files changed, 30 insertions(+), 93 deletions(-) delete mode 100644 generics/helpers/cache.js diff --git a/generics/helpers/cache.js b/generics/helpers/cache.js deleted file mode 100644 index 603d1a29..00000000 --- a/generics/helpers/cache.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * name : cache.js - * author : Priyanka Pradeep - * created-date : 21-Feb-2020 - * Description : Cache set , get and remove functionality. - */ - - const nodeCache = require( "node-cache" ); - const cache = new nodeCache(); - - /** - * Get cache data. - * @method - * @name get - Get specific cache data - * @params key - name of the cache key. - * @returns {Array} - return specific cache data. -*/ - -function getValue(key){ - let data = []; - - if (cache.has(key)) { - data = cache.get(key); - } - - return data; -} - - - /** - * Set new cache data - * @method - * @name set - * @params key - name of the cache key. - * @params value - cache data to set. - * @returns {Array} - cache updated data. -*/ - -function setValue(key, value, timeout){ - let data = cache.set( key, value, timeout ); - return data; -} - -/** - * delete cache data - * @method - * @name remove - * @params key - cache key need to be removed. - * @returns -*/ - -function removeKey(key){ - - let data = cache.del(key); - return; -} - -module.exports = { - getValue : getValue, - setValue : setValue, - removeKey : removeKey -} \ No newline at end of file diff --git a/generics/services/users.js b/generics/services/users.js index c19e9273..c5e5a04d 100644 --- a/generics/services/users.js +++ b/generics/services/users.js @@ -8,7 +8,6 @@ //dependencies const request = require('request'); const userServiceUrl = process.env.USER_SERVICE_URL; -const serverTimeout = CONSTANTS.common.SERVER_TIME_OUT; const profile = function ( token,userId = "" ) { return new Promise(async (resolve, reject) => { @@ -66,10 +65,11 @@ const profile = function ( token,userId = "" ) { * @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 ) { +const locationSearch = function ( filterData, formatResult = false ) { return new Promise(async (resolve, reject) => { try { @@ -86,7 +86,7 @@ const locationSearch = function ( filterData ) { }; request.post(url,options,requestCallback); - + let result = { success : true }; @@ -102,8 +102,27 @@ const locationSearch = function ( filterData ) { response.result.response && response.result.response.length > 0 ) { - result["data"] = response.result.response; - result["count"] = response.result.count; + 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; } @@ -115,7 +134,7 @@ const locationSearch = function ( filterData ) { return resolve (result = { success : false }); - }, serverTimeout); + }, CONSTANTS.common.SERVER_TIME_OUT); } catch (error) { return reject(error); diff --git a/module/reports/helper.js b/module/reports/helper.js index 144a5f24..a07f2ec5 100644 --- a/module/reports/helper.js +++ b/module/reports/helper.js @@ -320,7 +320,6 @@ module.exports = class ReportsHelper { } } catch (error) { - console.log("error : ",error) return resolve({ success: false, diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index a481f135..de6e4b76 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -2692,7 +2692,7 @@ function _entitiesInformation(entityIds) { let bodyData = { "id" : locationIds } - let entityData = await userProfileService.locationSearch( bodyData ); + let entityData = await userProfileService.locationSearch( bodyData, formatResult = true); if ( entityData.success ) { entityInformations = entityData.data; } @@ -2702,7 +2702,7 @@ function _entitiesInformation(entityIds) { let bodyData = { "code" : locationCodes } - let entityData = await userProfileService.locationSearch( bodyData ); + let entityData = await userProfileService.locationSearch( bodyData , formatResult = true ); if ( entityData.success ) { entityInformations = entityInformations.concat(entityData.data); } @@ -2714,30 +2714,11 @@ function _entitiesInformation(entityIds) { message: CONSTANTS.apiResponses.ENTITY_NOT_FOUND } } - - let entityResult = []; - //formating response - entityInformations.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); - }); - - let entitiesData = []; - - if ( entityResult.length > 0 ) { - - entitiesData = _entitiesMetaInformation(entityResult); + if ( entityInformations.length > 0 ) { + entitiesData = _entitiesMetaInformation(entityInformations); } - + return resolve({ success: true, data: entitiesData