Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #90

Merged
merged 4 commits into from
Jan 2, 2025
Merged
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
41 changes: 29 additions & 12 deletions src/module/entities/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,30 +168,46 @@ module.exports = class UserProjectsHelper {
// 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
const key = ['groups', type]
// create filter for fetching the parent data using group
let entityFilter = {}
entityFilter[key] = {
entityFilter[key.join('.')] = {
$in: entityIds,
}

// Retrieve all the entity documents with the entity ids in their gropu
const entityDocuments = await entitiesQueries.entityDocuments(entityFilter, [
'entityType',
'metaInformation.name',
key,
'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 }
// iterate through the data fetched to fetch the parent entity names
entityDocuments.forEach((eachEntity) => {
eachEntity[key.split('.')[0]][key.split('.')[1]].forEach((eachEntityGroup) => {
if (ObjectId(eachEntityGroup).equals(cloneData._id)) {
cloneData[eachEntity?.entityType] = eachEntity?.metaInformation?.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)
) {
cloneData[eachEntity?.entityType] = eachEntity?.metaInformation?.name
}
})
})
})
}
cloneData['label'] = cloneData.name
cloneData['value'] = cloneData._id
return cloneData
Expand Down Expand Up @@ -286,7 +302,7 @@ module.exports = class UserProjectsHelper {
status: CONSTANTS.common.ACTIVE_STATUS,
}
// Specify the fields to include in the result set
const userRoleExtensionProjection = ['_id', 'title', 'userRoleId']
const userRoleExtensionProjection = ['_id', 'title', 'code', 'userRoleId']

// Fetch the user roles based on the filter and projection
const fetchUserRoles = await userRoleExtensionHelper.find(
Expand All @@ -311,6 +327,7 @@ module.exports = class UserProjectsHelper {
_id: item._id,
value: item.userRoleId,
label: item.title,
code: item.code,
}
})
return resolve({
Expand Down