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
17 changes: 9 additions & 8 deletions backend/src/api/angor/angor.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ class AngorRoutes {
}
}

if (typeof queryOffset === 'string') {
if (typeof queryOffset === 'string' && queryOffset !== '') {
// Convert query param into number.
offset = parseInt(queryOffset);
const parsedOffset = parseInt(queryOffset);

// Validate offset query param.
if (Number.isNaN(offset)) {
if (Number.isNaN(parsedOffset)) {
this.responseWithValidationError(res, {
limit: [`The value '${queryOffset}' is not valid.`],
offset: [`The value '${queryOffset}' is not valid.`],
});

return;
} else if (offset < 0) {
} else if (parsedOffset < 0) {
this.responseWithValidationError(res, {
offset: [
'The field offset must be between 0 and 9.223372036854776E+18.',
Expand All @@ -145,6 +145,7 @@ class AngorRoutes {

return;
}
offset = parsedOffset;
}

// Angor projects.
Expand Down Expand Up @@ -360,14 +361,14 @@ class AngorRoutes {
}
}

if (typeof queryOffset === 'string') {
if (typeof queryOffset === 'string' && queryOffset !== '' && queryOffset !== '0') {
Copy link

Copilot AI Mar 14, 2025

Choose a reason for hiding this comment

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

The added condition "queryOffset !== '0'" may cause an explicit offset value of '0' to bypass validation, which seems inconsistent with the intended default handling. Consider revisiting this condition to ensure that an explicit '0' is processed uniformly.

Suggested change
if (typeof queryOffset === 'string' && queryOffset !== '' && queryOffset !== '0') {
if (typeof queryOffset === 'string' && queryOffset !== '') {

Copilot uses AI. Check for mistakes.
// Convert query param into number.
offset = parseInt(queryOffset);

// Validate offset query param.
if (Number.isNaN(offset)) {
this.responseWithValidationError(res, {
limit: [`The value '${queryOffset}' is not valid.`],
offset: [`The value '${queryOffset}' is not valid.`],
});

return;
Expand Down Expand Up @@ -490,7 +491,7 @@ class AngorRoutes {
let link = '<';

// 1st pagination chunk.
const firstChunk = path + `?offset=${0}&limit=${limit}`;
const firstChunk = path + `?offset=0&limit=${limit}`;

link += firstChunk;
link += '>; rel="first"';
Expand Down
Loading