From f7f942d08d63eb80f49bb7afbb175c83f62244c8 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 14 Sep 2025 09:45:55 +0200 Subject: [PATCH] Bugfix/fix pagination issue in market data and user endpoint by adding secondary sort criterion (#5521) * Add id as secondary sort criterion to ensure consistent ordering * Refactoring * Update changelog --- CHANGELOG.md | 5 ++++ apps/api/src/app/admin/admin.service.ts | 34 +++++++++++++++---------- apps/api/src/app/order/order.service.ts | 12 ++++----- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a557d40f..962bcf07f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Refactored the login with access token dialog component to standalone - Prefixed the `crypto`, `fs` and `path` imports with `node:` +### Fixed + +- Fixed a pagination issue in the market data endpoint by adding `id` as a secondary sort criterion to ensure consistent ordering in the admin control panel +- Fixed a pagination issue in the user endpoint by adding `id` as a secondary sort criterion to ensure consistent ordering in the admin control panel + ## 2.198.0 - 2025-09-11 ### Changed diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index 2918d9d7d..11f6f0599 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -192,7 +192,7 @@ export class AdminService { filters, presetId, sortColumn, - sortDirection, + sortDirection = 'asc', skip, take = Number.MAX_SAFE_INTEGER }: { @@ -262,11 +262,13 @@ export class AdminService { orderBy = [{ [sortColumn]: sortDirection }]; if (sortColumn === 'activitiesCount') { - orderBy = { - activities: { - _count: sortDirection + orderBy = [ + { + activities: { + _count: sortDirection + } } - }; + ]; } } @@ -275,10 +277,10 @@ export class AdminService { try { const symbolProfileResult = await Promise.all([ extendedPrismaClient.symbolProfile.findMany({ - orderBy, skip, take, where, + orderBy: [...orderBy, { id: sortDirection }], select: { _count: { select: { @@ -817,17 +819,21 @@ export class AdminService { skip?: number; take?: number; }): Promise { - let orderBy: Prisma.UserOrderByWithRelationInput = { - createdAt: 'desc' - }; + let orderBy: Prisma.Enumerable = [ + { createdAt: 'desc' } + ]; + let where: Prisma.UserWhereInput; if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { - orderBy = { - analytics: { - lastRequestAt: 'desc' + orderBy = [ + { + analytics: { + lastRequestAt: 'desc' + } } - }; + ]; + where = { NOT: { analytics: null @@ -836,10 +842,10 @@ export class AdminService { } const usersWithAnalytics = await this.prismaService.user.findMany({ - orderBy, skip, take, where, + orderBy: [...orderBy, { id: 'desc' }], select: { _count: { select: { accounts: true, activities: true } diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index fd50f5e74..11579bbf1 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -325,7 +325,7 @@ export class OrderService { includeDrafts = false, skip, sortColumn, - sortDirection, + sortDirection = 'asc', startDate, take = Number.MAX_SAFE_INTEGER, types, @@ -347,9 +347,9 @@ export class OrderService { withExcludedAccountsAndActivities?: boolean; }): Promise { let orderBy: Prisma.Enumerable = [ - { date: 'asc' }, - { id: 'asc' } + { date: 'asc' } ]; + const where: Prisma.OrderWhereInput = { userId }; if (endDate || startDate) { @@ -483,7 +483,7 @@ export class OrderService { } if (sortColumn) { - orderBy = [{ [sortColumn]: sortDirection }, { id: sortDirection }]; + orderBy = [{ [sortColumn]: sortDirection }]; } if (types) { @@ -506,7 +506,6 @@ export class OrderService { const [orders, count] = await Promise.all([ this.orders({ - orderBy, skip, take, where, @@ -519,7 +518,8 @@ export class OrderService { // eslint-disable-next-line @typescript-eslint/naming-convention SymbolProfile: true, tags: true - } + }, + orderBy: [...orderBy, { id: sortDirection }] }), this.prismaService.order.count({ where }) ]);