Skip to content

Commit

Permalink
review change
Browse files Browse the repository at this point in the history
  • Loading branch information
VISHNUDAS-tunerlabs committed Aug 23, 2022
1 parent 7478444 commit 0b2478c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 93 deletions.
62 changes: 0 additions & 62 deletions generics/helpers/cache.js

This file was deleted.

31 changes: 25 additions & 6 deletions generics/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 {

Expand All @@ -86,7 +86,7 @@ const locationSearch = function ( filterData ) {
};

request.post(url,options,requestCallback);

let result = {
success : true
};
Expand All @@ -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;
}
Expand All @@ -115,7 +134,7 @@ const locationSearch = function ( filterData ) {
return resolve (result = {
success : false
});
}, serverTimeout);
}, CONSTANTS.common.SERVER_TIME_OUT);

} catch (error) {
return reject(error);
Expand Down
1 change: 0 additions & 1 deletion module/reports/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ module.exports = class ReportsHelper {

}
} catch (error) {
console.log("error : ",error)
return resolve({

success: false,
Expand Down
29 changes: 5 additions & 24 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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
Expand Down

0 comments on commit 0b2478c

Please sign in to comment.