Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/generics/constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ module.exports = {
ORG_ADMIN: 'org_admin',
TENANT_ADMIN: 'tenant_admin',
SERVER_TIME_OUT: 5000,
GUEST_URLS: ['/entities/details'],
GUEST_URLS: ['/entities/details', '/entities/entityListBasedOnEntityType', 'entities/subEntityList'],
}
13 changes: 13 additions & 0 deletions src/generics/middleware/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ module.exports = async function (req, res, next, token = '') {
)

if (guestAccess == true && !token) {
if (!req.headers['tenantid']) {
rspObj.errCode = CONSTANTS.apiResponses.TOKEN_MISSING_CODE
rspObj.errMsg = CONSTANTS.apiResponses.TOKEN_MISSING_MESSAGE
rspObj.responseCode = HTTP_STATUS_CODE['unauthorized'].status
return res.status(HTTP_STATUS_CODE['unauthorized'].status).send(respUtil(rspObj))
}
req.userDetails = {
userInformation: {
tenantId: req.headers['tenantid'],
organizationId: req.headers['orgid'] || null,
},
}

next()
return
}
Expand Down
108 changes: 54 additions & 54 deletions src/module/entities/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,60 +252,60 @@ module.exports = class UserProjectsHelper {
}

// Modify data properties (e.g., 'label') of retrieved entities if necessary
if (result.data && result.data.length > 0) {
// fetch the entity ids to look for parent hierarchy
const entityIds = _.map(result.data, (item) => ObjectId(item._id))
// dynamically set the entityType to search inside the group
const key = ['groups', type]
// create filter for fetching the parent data using group
let entityFilter = {}
entityFilter[key.join('.')] = {
$in: entityIds,
}

entityFilter['tenantId'] = tenantId

// Retrieve all the entity documents with the entity ids in their gropu
const entityDocuments = await entitiesQueries.entityDocuments(entityFilter, [
'entityType',
'metaInformation.name',
'childHierarchyPath',
key.join('.'),
])
// find out the state of the passed entityId
const stateEntity = entityDocuments.find((entity) => entity.entityType == 'state')
// fetch the child hierarchy path of the state
const stateChildHierarchy = stateEntity.childHierarchyPath
let upperLevelsOfType = type != 'state' ? ['state'] : [] // add state as default if type != state
// fetch all the upper levels of the type from state hierarchy
upperLevelsOfType = [
...upperLevelsOfType,
...stateChildHierarchy.slice(0, stateChildHierarchy.indexOf(type)),
]
result.data = result.data.map((data) => {
let cloneData = { ...data }
cloneData[cloneData.entityType] = cloneData.name
// if we have upper levels to fetch
if (upperLevelsOfType.length > 0) {
// iterate through the data fetched to fetch the parent entity names
entityDocuments.forEach((eachEntity) => {
eachEntity[key[0]][key[1]].forEach((eachEntityGroup) => {
if (
ObjectId(eachEntityGroup).equals(cloneData._id) &&
upperLevelsOfType.includes(eachEntity.entityType)
) {
if (eachEntity?.entityType !== 'state') {
cloneData[eachEntity?.entityType] = eachEntity?.metaInformation?.name
}
}
})
})
}
cloneData['label'] = cloneData.name
cloneData['value'] = cloneData._id
return cloneData
})
}
// if (result.data && result.data.length > 0) {
// // fetch the entity ids to look for parent hierarchy
// const entityIds = _.map(result.data, (item) => ObjectId(item._id))
// // dynamically set the entityType to search inside the group
// const key = ['groups', type]
// // create filter for fetching the parent data using group
// let entityFilter = {}
// entityFilter[key.join('.')] = {
// $in: entityIds,
// }

// entityFilter['tenantId'] = tenantId

// // Retrieve all the entity documents with the entity ids in their gropu
// const entityDocuments = await entitiesQueries.entityDocuments(entityFilter, [
// 'entityType',
// 'metaInformation.name',
// 'childHierarchyPath',
// key.join('.'),
// ])
// // find out the state of the passed entityId
// const stateEntity = entityDocuments.find((entity) => entity.entityType == 'state')
// // fetch the child hierarchy path of the state
// const stateChildHierarchy = stateEntity.childHierarchyPath
// let upperLevelsOfType = type != 'state' ? ['state'] : [] // add state as default if type != state
// // fetch all the upper levels of the type from state hierarchy
// upperLevelsOfType = [
// ...upperLevelsOfType,
// ...stateChildHierarchy.slice(0, stateChildHierarchy.indexOf(type)),
// ]
// result.data = result.data.map((data) => {
// let cloneData = { ...data }
// cloneData[cloneData.entityType] = cloneData.name
// // if we have upper levels to fetch
// if (upperLevelsOfType.length > 0) {
// // iterate through the data fetched to fetch the parent entity names
// entityDocuments.forEach((eachEntity) => {
// eachEntity[key[0]][key[1]].forEach((eachEntityGroup) => {
// if (
// ObjectId(eachEntityGroup).equals(cloneData._id) &&
// upperLevelsOfType.includes(eachEntity.entityType)
// ) {
// if (eachEntity?.entityType !== 'state') {
// cloneData[eachEntity?.entityType] = eachEntity?.metaInformation?.name
// }
// }
// })
// })
// }
// cloneData['label'] = cloneData.name
// cloneData['value'] = cloneData._id
// return cloneData
// })
// }

resolve({
message: CONSTANTS.apiResponses.ENTITIES_FETCHED,
Expand Down