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
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@
}
],
"url": {
"raw": "{{baseUrl}}/entity/v1/entities/targetedRoles/5f33c3d85f637784791cd831",
"raw": "{{baseUrl}}/entity/v1/entities/targetedRoles/5f33c3d85f637784791cd831?entityType=district",
"host": ["{{baseUrl}}"],
"path": ["entity", "v1", "entities", "targetedRoles", "5f33c3d85f637784791cd831"]
}
Expand Down
6 changes: 6 additions & 0 deletions src/api-doc/api-doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,12 @@ paths:
schema:
type: string
required: true
- in: query
name: entityType
description: Please append a valid entity type to retrieve the roles associated with its higher-level entity types.
schema:
type: string
required: true
responses:
'200':
description: Accepted
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/v1/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ module.exports = class Entities extends Abstract {
req.params._id,
req.pageNo,
req.pageSize,
req?.query?.paginate?.toLowerCase() == 'true' ? true : false
req?.query?.paginate?.toLowerCase() == 'true' ? true : false,
req.query.entityType ? req.query.entityType : ''
)
// Resolves the promise with the retrieved entity data
return resolve(userRoleDetails)
Expand Down
18 changes: 15 additions & 3 deletions src/module/entities/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ module.exports = class UserProjectsHelper {
* @param {Array<string>} entityId - An array of entity IDs to filter roles.
* @param {params} pageSize - page pageSize.
* @param {params} pageNo - page no.
* @param {String} type - Entity type
* @returns {Promise<Object>} A promise that resolves to the response containing the fetched roles or an error object.
*/
static targetedRoles(entityId, pageNo = '', pageSize = '', paginate) {
static targetedRoles(entityId, pageNo = '', pageSize = '', paginate, type = "") {
return new Promise(async (resolve, reject) => {
try {
// Construct the filter to retrieve entities based on provided entity IDs
Expand All @@ -227,6 +228,7 @@ module.exports = class UserProjectsHelper {
const projectionFields = ['childHierarchyPath', 'entityType']
// Retrieve entityDetails based on provided entity IDs
const entityDetails = await entitiesQueries.entityDocuments(filter, projectionFields)

if (
!entityDetails ||
!entityDetails[0]?.childHierarchyPath ||
Expand All @@ -241,12 +243,22 @@ module.exports = class UserProjectsHelper {
const { childHierarchyPath, entityType } = entityDetails[0]

// Append entityType to childHierarchyPath array
const updatedChildHierarchyPaths = [...childHierarchyPath, entityType]
const updatedChildHierarchyPaths = [entityType, ...childHierarchyPath]

// Filter for higher entity types if a specific type is requested
let filteredHierarchyPaths = updatedChildHierarchyPaths
if (type) {
const typeIndex = updatedChildHierarchyPaths.indexOf(type)
if (typeIndex > -1) {
// Include only higher types in the hierarchy
filteredHierarchyPaths = updatedChildHierarchyPaths.slice(0, typeIndex + 1)
}
}

// Construct the filter to retrieve entity type IDs based on child hierarchy paths
const entityTypeFilter = {
name: {
$in: updatedChildHierarchyPaths,
$in: filteredHierarchyPaths,
},
isDeleted: false,
}
Expand Down