-
Notifications
You must be signed in to change notification settings - Fork 28
Refactor mentees.js for enhanced query processing and validation - BUG 4416 #1597
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
+1529
to
+1534
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the correct tenant error message key Line 1529 validates 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard entity-type cache failures before building filters Line 1536 can return an 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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(',') : [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid a hard failure on an unused defaults lookup
defaultsis fetched and validated, but not used afterwards inlist. This adds an unrelated failure path for Line 1504 endpoint behavior and can block mentee listing unnecessarily.Proposed fix
🤖 Prompt for AI Agents