Skip to content

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

Merged
merged 7 commits into from
Aug 19, 2025

Conversation

hentrymartin
Copy link
Collaborator

What's in this PR?

  • Paginate copilot request API

Ticket link - https://topcoder.atlassian.net/browse/PM-1650

@@ -15,6 +17,10 @@ module.exports = [
return next(err);
}

const page = parseInt(req.query.page, 10) || 1;

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;

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({

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 },

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, {

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.

@hentrymartin hentrymartin requested a review from kkartunov August 17, 2025 22:03
@hentrymartin hentrymartin merged commit ea6cd97 into develop Aug 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant