-
Notifications
You must be signed in to change notification settings - Fork 55
fix(PM-1650): Paginate copilot request API #848
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
Conversation
@@ -15,6 +17,10 @@ module.exports = [ | |||
return next(err); | |||
} | |||
|
|||
const page = parseInt(req.query.page, 10) || 1; |
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.
Consider adding validation for req.query.page
to ensure it is a positive integer. This will prevent potential issues if a non-numeric or negative value is provided.
@@ -15,6 +17,10 @@ module.exports = [ | |||
return next(err); | |||
} | |||
|
|||
const page = parseInt(req.query.page, 10) || 1; | |||
const pageSize = parseInt(req.query.pageSize, 10) || DEFAULT_PAGE_SIZE; |
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.
Consider adding validation for req.query.pageSize
to ensure it is a positive integer. This will prevent potential issues if a non-numeric or negative value is provided.
@@ -29,19 +35,22 @@ module.exports = [ | |||
|
|||
const whereCondition = projectId ? { projectId } : {}; | |||
|
|||
return models.CopilotRequest.findAll({ | |||
return models.CopilotRequest.findAndCountAll({ |
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.
Consider checking if projectId
is valid before using it in the whereCondition
to prevent potential errors.
model: models.CopilotOpportunity, | ||
as: 'copilotOpportunity', | ||
}, | ||
{ model: models.CopilotOpportunity, as: 'copilotOpportunity', required: false }, |
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.
The required: false
option in the include
statement for CopilotOpportunity
and Project
models might lead to unexpected results if the associations are not optional. Ensure that this behavior is intended.
offset, | ||
distinct: true, | ||
subQuery: false, | ||
}).then(({rows: copilotRequests, count}) => util.setPaginationHeaders(req, res, { |
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.
The function util.setPaginationHeaders
is used to set pagination headers. Ensure that this function correctly handles edge cases, such as when count
is zero or pageSize
is larger than the total number of items.
What's in this PR?
Ticket link - https://topcoder.atlassian.net/browse/PM-1650