Skip to content
Open
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/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ function parseMetaData(meta = {}, prunedEntities, feederData) {
// find the entity type from the entities array with the value of the entity
const findEntity = prunedEntities.find((entity) => entity.value == metaKey)
// check the data type of the entity to loop in Array type entities
if (findEntity.data_type == 'ARRAY' || findEntity.data_type == 'ARRAY[STRING]') {
if (findEntity && (findEntity.data_type == 'ARRAY' || findEntity.data_type == 'ARRAY[STRING]')) {
metaData[metaKey] = meta?.[metaKey].map((entity) => {
const id = getId(entity) // get the id from the input
const find = Object.values(feederData).find(
Expand Down
55 changes: 48 additions & 7 deletions src/helpers/userInvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,54 @@ module.exports = class UserInviteHelper {
: [],
}

delete row.block
delete row.state
delete row.school
delete row.cluster
delete row.district
delete row.professional_role
delete row.professional_subroles
// 2. Handle dynamic entityFields (skipping what we already did)
const alreadyProcessed = [
'block',
'state',
'school',
'cluster',
'district',
'professional_role',
'professional_subroles',
]

entityFields.forEach((field) => {
// 1. Skip if already handled in the hardcoded block
if (alreadyProcessed.includes(field)) return

// 2. Only process if the row actually has data for this field
if (row[field]) {
// Find the definition to check if it's an ARRAY type
const entityDef = validationData.find((e) => e.value === field)
const cleanField = field.replaceAll(/\s+/g, '').toLowerCase()

if (
entityDef &&
(entityDef.data_type === 'ARRAY' || entityDef.data_type === 'ARRAY[STRING]')
) {
// Handle ARRAY types: split by comma, clean each value, and map to IDs
row.meta[field] = row[field]
.split(',')
.map((val) => {
const cleanVal = val.trim().replaceAll(/\s+/g, '').toLowerCase()
const lookupKey = `${cleanVal}${cleanField}`
return externalEntityNameIdMap?.[lookupKey]?._id
})
.filter(Boolean) // Removes null/undefined if an ID isn't found
} else {
// Handle Single value types (Standard logic)
const cleanVal = String(row[field]).replaceAll(/\s+/g, '').toLowerCase()
const lookupKey = `${cleanVal}${cleanField}`
row.meta[field] = externalEntityNameIdMap?.[lookupKey]?._id || null
}
}
})

// 3. Delete all processed fields from the root row
const allFieldsToDelete = [...alreadyProcessed, ...entityFields]
allFieldsToDelete.forEach((field) => {
delete row[field]
})

// Handle password field if exists
if (row.password) {
Expand Down