Skip to content
Open
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
49 changes: 21 additions & 28 deletions src/services/mentees.js
Original file line number Diff line number Diff line change
Expand Up @@ -1525,17 +1525,33 @@ module.exports = class MenteesHelper {
const query = utils.processQueryParametersWithExclusions(queryParams)
const userExtensionModelName = await menteeQueries.getModelName()

const defaults = await getDefaults()
if (!defaults.tenantCode)
return responses.failureResponse({
message: 'DEFAULT_ORG_CODE_NOT_SET',
statusCode: httpStatusCode.bad_request,
responseCode: 'CLIENT_ERROR',
})
Comment on lines +1528 to +1534
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid a hard failure on an unused defaults lookup

defaults is fetched and validated, but not used afterwards in list. This adds an unrelated failure path for Line 1504 endpoint behavior and can block mentee listing unnecessarily.

Proposed fix
-const defaults = await getDefaults()
-if (!defaults.tenantCode)
-	return responses.failureResponse({
-		message: 'DEFAULT_ORG_CODE_NOT_SET',
-		statusCode: httpStatusCode.bad_request,
-		responseCode: 'CLIENT_ERROR',
-	})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/mentees.js` around lines 1528 - 1534, The list handler in
src/services/mentees.js currently calls getDefaults() and returns a hard failure
if defaults.tenantCode is missing even though defaults isn't used later; remove
the unnecessary failure path by either deleting the getDefaults() call entirely
from the list flow or by making the lookup non-blocking (e.g., catch errors and
ignore missing tenantCode) so the list function proceeds normally; update the
code around getDefaults, the conditional checking defaults.tenantCode, and any
related responses.failureResponse usage to ensure list continues without
returning DEFAULT_ORG_CODE_NOT_SET.

Comment on lines +1529 to +1534
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use the correct tenant error message key

Line 1529 validates defaults.tenantCode, but Lines 1531-1534 return DEFAULT_ORG_CODE_NOT_SET. This returns a misleading client error for tenant misconfiguration.

Proposed fix
 if (!defaults.tenantCode)
 	return responses.failureResponse({
-		message: 'DEFAULT_ORG_CODE_NOT_SET',
+		message: 'DEFAULT_TENANT_CODE_NOT_SET',
 		statusCode: httpStatusCode.bad_request,
 		responseCode: 'CLIENT_ERROR',
 	})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!defaults.tenantCode)
return responses.failureResponse({
message: 'DEFAULT_ORG_CODE_NOT_SET',
statusCode: httpStatusCode.bad_request,
responseCode: 'CLIENT_ERROR',
})
if (!defaults.tenantCode)
return responses.failureResponse({
message: 'DEFAULT_TENANT_CODE_NOT_SET',
statusCode: httpStatusCode.bad_request,
responseCode: 'CLIENT_ERROR',
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/mentees.js` around lines 1529 - 1534, The check for
defaults.tenantCode returns a misleading error key 'DEFAULT_ORG_CODE_NOT_SET';
update the responses.failureResponse call in the block that validates
defaults.tenantCode (where responses.failureResponse is invoked with message:
'DEFAULT_ORG_CODE_NOT_SET') to use the correct tenant-specific message key
(e.g., 'DEFAULT_TENANT_CODE_NOT_SET' or the existing tenant error constant from
your error messages) while keeping the same statusCode and responseCode; ensure
you reference the tenant error constant if available instead of a hard-coded
string.


let validationData = await entityTypeCache.getEntityTypesAndEntitiesWithCache(
{
status: common.ACTIVE_STATUS,
model_names: { [Op.overlap]: [userExtensionModelName] },
},
tenantCode,
organizationCode,
userExtensionModelName
)

let filteredQuery = utils.validateAndBuildFilters(query, validationData)

Comment on lines +1536 to +1547
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard entity-type cache failures before building filters

Line 1536 can return an Error object (pattern already handled elsewhere in this file), but Line 1546 immediately passes the result into validateAndBuildFilters. Add an explicit guard to prevent invalid filter construction.

Proposed fix
 let validationData = await entityTypeCache.getEntityTypesAndEntitiesWithCache(
 	{
 		status: common.ACTIVE_STATUS,
 		model_names: { [Op.overlap]: [userExtensionModelName] },
 	},
 	tenantCode,
 	organizationCode,
 	userExtensionModelName
 )
+if (validationData instanceof Error) {
+	throw validationData
+}

 let filteredQuery = utils.validateAndBuildFilters(query, validationData)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let validationData = await entityTypeCache.getEntityTypesAndEntitiesWithCache(
{
status: common.ACTIVE_STATUS,
model_names: { [Op.overlap]: [userExtensionModelName] },
},
tenantCode,
organizationCode,
userExtensionModelName
)
let filteredQuery = utils.validateAndBuildFilters(query, validationData)
let validationData = await entityTypeCache.getEntityTypesAndEntitiesWithCache(
{
status: common.ACTIVE_STATUS,
model_names: { [Op.overlap]: [userExtensionModelName] },
},
tenantCode,
organizationCode,
userExtensionModelName
)
if (validationData instanceof Error) {
throw validationData
}
let filteredQuery = utils.validateAndBuildFilters(query, validationData)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/mentees.js` around lines 1536 - 1547, The result of
entityTypeCache.getEntityTypesAndEntitiesWithCache (assigned to validationData)
can be an Error; before calling utils.validateAndBuildFilters you must guard
that validationData is not an Error. Add an explicit check after the
getEntityTypesAndEntitiesWithCache call (e.g., if (validationData instanceof
Error) { ... }) and handle it the same way other sections in this file do
(returning/propagating the error or logging and exiting) so that
utils.validateAndBuildFilters is only called with valid validation data.

let connectedMenteeIds = []
let connectedMenteesCount
if (queryParams.connected_mentees === 'true') {
const connectedQueryParams = { ...queryParams }
delete connectedQueryParams.connected_mentees
const connectedQuery = utils.processQueryParametersWithExclusions(connectedQueryParams)

const connectionDetails = await connectionQueries.getConnectionsDetails(
pageNo,
pageSize,
connectedQuery,
filteredQuery,
searchText,
queryParams.mentorId ? queryParams.mentorId : userId,
organization_codes,
Expand All @@ -1547,9 +1563,6 @@ module.exports = class MenteesHelper {
pageNo = null
pageSize = null
connectedMenteeIds = connectionDetails.data.map((item) => item.user_id)
// if (!connectedMenteeIds.includes(userId)) {
// connectedMenteeIds.push(userId)
// }
}
if (typeof connectionDetails?.count === 'number') {
connectedMenteesCount = connectionDetails.count
Expand All @@ -1568,26 +1581,6 @@ module.exports = class MenteesHelper {
}
}

const defaults = await getDefaults()
if (!defaults.tenantCode)
return responses.failureResponse({
message: 'DEFAULT_ORG_CODE_NOT_SET',
statusCode: httpStatusCode.bad_request,
responseCode: 'CLIENT_ERROR',
})

let validationData = await entityTypeCache.getEntityTypesAndEntitiesWithCache(
{
status: common.ACTIVE_STATUS,
model_names: { [Op.overlap]: [userExtensionModelName] },
},
tenantCode,
organizationCode,
userExtensionModelName
)

let filteredQuery = utils.validateAndBuildFilters(query, validationData)

const emailIds = []
const searchTextArray = searchText ? searchText.split(',') : []

Expand Down