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
173 changes: 127 additions & 46 deletions src/api-doc/api-doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,25 @@ paths:
items:
type: object
properties:
metaInformation:
type: object
properties:
targetedEntityTypes:
type: array
items:
type: object
properties:
entityType:
type: string
entityTypeId:
type: string
required:
- entityType
- entityTypeId
externalId:
type: string
name:
type: string
childHierarchyPath:
type: array
items:
Expand All @@ -898,6 +917,10 @@ paths:
type: string
updatedBy:
type: string
orgIds:
type: array
items:
type: string
_id:
type: string
deleted:
Expand All @@ -913,11 +936,10 @@ paths:
type: string
code:
type: string
metaInformation:
type: object
properties:
externalId:
type: string
userId:
type: string
tenantId:
type: string
updatedAt:
type: string
createdAt:
Expand All @@ -930,25 +952,34 @@ paths:
message: ENTITY_ADDED
status: 200
result:
- childHierarchyPath:
- metaInformation:
targetedEntityTypes:
- entityType: state
entityTypeId: 683953548f365ab56c8022e9
- entityType: block
entityTypeId: 6839535b8f365ab56c8022ed
externalId: KA28
name: Karnataka
childHierarchyPath:
- district
- beat
- block
- cluster
- school
- block
createdBy: SYSTEM
updatedBy: SYSTEM
_id: 6634b0767411a605fdbaca71
createdBy: '208'
updatedBy: '208'
orgIds:
- ALL
_id: 683996e732316a1ac4f6f150
deleted: false
entityTypeId: 5f32d8228e0dc83124040567
entityType: school
entityTypeId: 683953808f365ab56c8022f5
entityType: professional_role
registryDetails:
locationId: entity123
code: entity123
metaInformation:
externalId: entity123
updatedAt: '2024-05-03T09:37:58.425Z'
createdAt: '2024-05-03T09:37:58.425Z'
locationId: KA28
code: KA28
userId: '208'
tenantId: '24'
updatedAt: '2025-05-30T11:30:47.909Z'
createdAt: '2025-05-30T11:30:47.909Z'
__v: 0
'400':
description: Bad Request.
Expand Down Expand Up @@ -979,22 +1010,26 @@ paths:
type: string
name:
type: string
entityType:
type: string
childHierarchyPath:
type: array
items:
type: string
targetedEntityTypes:
type: array
items:
type: string
examples:
sampleBodyData:
value:
externalId: entity123
name: entityName
externalId: KA28
name: Karnataka
childHierarchyPath:
- district
- beat
- block
- cluster
- school
targetedEntityTypes:
- state
- block
/v1/entities/details/{_id}?&language={code}:
get:
Expand Down Expand Up @@ -1148,8 +1183,29 @@ paths:
metaInformation:
type: object
properties:
targetedEntityTypes:
type: array
items:
type: object
properties:
entityType:
type: string
entityTypeId:
type: string
required:
- entityType
- entityTypeId
externalId:
type: string
name:
type: string
registryDetails:
type: object
properties:
locationId:
type: string
code:
type: string
childHierarchyPath:
type: array
items:
Expand All @@ -1158,6 +1214,10 @@ paths:
type: string
updatedBy:
type: string
orgIds:
type: array
items:
type: string
deleted:
type: boolean
_id:
Expand All @@ -1166,6 +1226,10 @@ paths:
type: string
entityType:
type: string
userId:
type: string
tenantId:
type: string
updatedAt:
type: string
createdAt:
Expand All @@ -1175,24 +1239,33 @@ paths:
examples:
SuccessResponse:
value:
message: ENTITY_UPDATATED
message: ENTITY_UPDATED
status: 200
result:
metaInformation:
externalId: SCH
name: school
targetedEntityTypes:
- entityType: state
entityTypeId: 683953548f365ab56c8022e9
- entityType: block
entityTypeId: 6839535b8f365ab56c8022ed
externalId: KA28
name: Karnataka
registryDetails:
locationId: rajAPSTATEDummy4
code: rajAPSTATEDummy4
locationId: KA28
code: KA28
childHierarchyPath: []
createdBy: user123
updatedBy: user123
createdBy: '208'
updatedBy: '208'
orgIds:
- ALL
deleted: false
_id: 66ea64fa68cd063346a10365
entityTypeId: 6672ce0fc05aa58f89ba12f1
entityType: state
updatedAt: '2024-09-18T10:07:39.407Z'
createdAt: '2024-09-18T05:28:26.148Z'
_id: 68395a55e5af17c215ce3408
entityTypeId: 683953808f365ab56c8022f5
entityType: professional_role
userId: '208'
tenantId: '24'
updatedAt: '2025-05-30T11:32:35.296Z'
createdAt: '2025-05-30T07:12:21.457Z'
__v: 0
'400':
description: Bad Request.
Expand All @@ -1216,26 +1289,34 @@ paths:
schema:
type: object
properties:
metaInformation.externalId:
type: string
metaInformation.targetedEntityTypes:
type: array
items:
type: object
properties:
entityType:
type: string
entityTypeId:
type: string
required:
- entityType
- entityTypeId
metaInformation.name:
type: string
childHierarchyPath:
type: array
items:
type: string
createdBy:
type: string
updatedBy:
type: string
examples:
sampleBodyData:
value:
metaInformation.externalId: SCH
metaInformation.name: school
metaInformation.targetedEntityTypes:
- entityType: state
entityTypeId: 683953548f365ab56c8022e9
- entityType: block
entityTypeId: 6839535b8f365ab56c8022ed
metaInformation.name: 'Karnataka '
childHierarchyPath: []
createdBy: user123
updatedBy: user123
/v1/entities/mappingUpload:
post:
summary: This endpoint will map its childEntity to its parentEntity
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/v1/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ module.exports = class Entities extends Abstract {
translationFile = JSON.parse(req.files.translationFile.data.toString())
}
// Call 'entitiesHelper.bulkUpdate' to update entities based on CSV data and user details
let newEntityData = await entitiesHelper.bulkUpdate(entityCSVData, translationFile, userDetails)
let newEntityData = await entitiesHelper.bulkUpdate(entityCSVData, translationFile, req.userDetails)

// Check if entities were updated successfully
if (newEntityData.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions src/models/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
metaInformation: {
externalId: { type: String, index: true },
name: { type: String, index: true },
targetedEntityTypes: { type: Array },
},
childHierarchyPath: Array,
userId: {
Expand Down
59 changes: 58 additions & 1 deletion src/module/entities/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,12 @@ module.exports = class UserProjectsHelper {
// Convert the names in 'validatedChildHierarchy' to strings and assign them to 'childHierarchyPath'
childHierarchyPath = validatedChildHierarchy.map(String)
}

singleEntity.targetedEntityTypes = Array.isArray(singleEntity.targetedEntityTypes)
? await populateTargetedEntityTypesData(
singleEntity.targetedEntityTypes.map((item) => item.trim()),
tenantId
)
: []
// Construct the entity document to be created
let entityDoc = {
entityTypeId: entityTypeDocument._id,
Expand Down Expand Up @@ -1639,6 +1644,19 @@ module.exports = class UserProjectsHelper {
// entityCreation['allowedRoles'] = await allowedRoles(singleEntity.allowedRoles)
// delete singleEntity.allowedRoles
// }
let entityTypesArray = []
if (singleEntity.targetedEntityTypes) {
entityTypesArray = singleEntity.targetedEntityTypes
.replace(/^"(.*)"$/, '$1') // remove starting and ending quotes
.split(',')
.map((type) => type.trim())
}

singleEntity.targetedEntityTypes =
Array.isArray(entityTypesArray) && entityTypesArray.length > 0
? await populateTargetedEntityTypesData(entityTypesArray, tenantId)
: []

if (singleEntity.childHierarchyPath) {
entityCreation['childHierarchyPath'] = JSON.parse(singleEntity['childHierarchyPath'])
}
Expand Down Expand Up @@ -1792,6 +1810,15 @@ module.exports = class UserProjectsHelper {
updateData['translations'] = translationFile[updateData['metaInformation.name']]
}

let targetedEntityTypes = entityCSVData[0].targetedEntityTypes
.split(',')
.map((item) => item.trim())

updateData['metaInformation.targetedEntityTypes'] =
Array.isArray(targetedEntityTypes) && targetedEntityTypes.length > 0
? await populateTargetedEntityTypesData(targetedEntityTypes, tenantId)
: []

if (Object.keys(updateData).length > 0) {
let updateEntity = await entitiesQueries.findOneAndUpdate(
{ _id: singleEntity['_SYSTEM_ID'], tenantId: tenantId },
Expand Down Expand Up @@ -1858,6 +1885,14 @@ module.exports = class UserProjectsHelper {
}
}

if (bodyData['targetedEntityTypes']) {
bodyData.targetedEntityTypes = bodyData.targetedEntityTypes.map((item) => item.trim())
bodyData['metaInformation.targetedEntityTypes'] = await populateTargetedEntityTypesData(
bodyData.targetedEntityTypes,
tenantId
)
delete bodyData.targetedEntityTypes
}
// Update the entity using findOneAndUpdate
let entityInformation = await entitiesQueries.findOneAndUpdate(
{ _id: ObjectId(entityId), tenantId: tenantId },
Expand Down Expand Up @@ -2201,3 +2236,25 @@ function addTagsInEntities(entityMetaInformation) {
}
return entityMetaInformation
}

async function populateTargetedEntityTypesData(targetedEntityTypes, tenantId) {
try {
const formattedTargetedEntityTypes = await entityTypeQueries.entityTypesDocument(
{
name: { $in: targetedEntityTypes },
tenantId: tenantId,
},
['name', '_id']
)

formattedTargetedEntityTypes.forEach((entityType) => {
entityType['entityTypeId'] = entityType._id.toString()
entityType['entityType'] = entityType.name
delete entityType._id
delete entityType.name
})
return formattedTargetedEntityTypes
} catch (err) {
return []
}
}