diff --git a/src/modules/analytics/collections-analytics.resolver.ts b/src/modules/analytics/collections-analytics.resolver.ts index 67237e9fa..80853ab64 100644 --- a/src/modules/analytics/collections-analytics.resolver.ts +++ b/src/modules/analytics/collections-analytics.resolver.ts @@ -5,7 +5,7 @@ import { CollectionsAnalyticsModel } from './models/collections-stats.model'; import { BaseResolver } from '../common/base.resolver'; import { CollectionsAnalyticsResponse } from './models/collections-analytics.response'; import PageResponse from '../common/PageResponse'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import { CollectionDetailsProvider } from './loaders/collection-details.loader'; import { CollectionsDetailsModel } from './models/collections-details.model'; import { AnalyticsArgs, CollectionAnalyticsArgs } from './models/analytics-args.model'; @@ -26,7 +26,7 @@ export class CollectionsAnalyticsResolver extends BaseResolver(CollectionsAnalyt @Args('input', { type: () => CollectionAnalyticsArgs, nullable: true }) input: CollectionAnalyticsArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [collections, count] = await this.collectionsAnalyticsService.getCollectionsOrderByVolum(limit, offset, input.series); return PageResponse.mapResponse(collections || [], pagination, count || 0, 0, limit); } diff --git a/src/modules/artists/artists.resolver.ts b/src/modules/artists/artists.resolver.ts index 8f4b8ce9b..54c719391 100644 --- a/src/modules/artists/artists.resolver.ts +++ b/src/modules/artists/artists.resolver.ts @@ -1,6 +1,6 @@ import { Query, Resolver, Args } from '@nestjs/graphql'; import { Account } from '../account-stats/models'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { ArtistsService } from './artists.service'; import { ArtistFilters } from './models/Artists.Filter'; @@ -17,7 +17,7 @@ export class ArtistsResolver { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [accounts, count] = await this.artistsService.getArtists(filters, offset, limit); return PageResponse.mapResponse(accounts || [], pagination, count || 0, offset, limit); } diff --git a/src/modules/assets/asset-auction.resolver.ts b/src/modules/assets/asset-auction.resolver.ts index fcd455b67..bf58de7dd 100644 --- a/src/modules/assets/asset-auction.resolver.ts +++ b/src/modules/assets/asset-auction.resolver.ts @@ -4,7 +4,7 @@ import { Asset } from './models'; import { Auction, AuctionResponse } from '../auctions/models'; import { AuctionEntity } from 'src/db/auctions'; import { AuctionsForAssetProvider } from '../auctions/loaders/asset-auctions.loader'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; @Resolver(() => Asset) @@ -19,7 +19,7 @@ export class AssetAuctionResolver extends BaseResolver(Asset) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const { identifier } = asset; if (!identifier) { return null; diff --git a/src/modules/assets/assets-queries.resolver.ts b/src/modules/assets/assets-queries.resolver.ts index 09ccc02a8..e9a1b9b73 100644 --- a/src/modules/assets/assets-queries.resolver.ts +++ b/src/modules/assets/assets-queries.resolver.ts @@ -11,7 +11,7 @@ import { AssetsSupplyLoader } from './loaders/assets-supply.loader'; import { AssetScamInfoProvider } from './loaders/assets-scam-info.loader'; import { IsAssetLikedProvider } from './loaders/asset-is-liked.loader'; import { LowestAuctionProvider } from '../auctions/loaders/lowest-auctions.loader'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import { AssetsFilter } from '../common/filters/filtersTypes'; import PageResponse from '../common/PageResponse'; import { AssetsViewsLoader } from './loaders/assets-views.loader'; @@ -63,7 +63,7 @@ export class AssetsQueriesResolver extends BaseResolver(Asset) { @Args({ name: 'sorting', type: () => AssetsSortingEnum, nullable: true }) sorting: AssetsSortingEnum, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const response = await this.assetsService.getAssets(offset, limit, filters, sorting); return PageResponse.mapResponse(response?.items || [], pagination, response?.count || 0, offset, limit); diff --git a/src/modules/auctions/auction-orders.resolver.ts b/src/modules/auctions/auction-orders.resolver.ts index 33ea6a993..e81d3f9d3 100644 --- a/src/modules/auctions/auction-orders.resolver.ts +++ b/src/modules/auctions/auction-orders.resolver.ts @@ -4,7 +4,7 @@ import { AuctionsOrdersProvider } from '.'; import { Auction } from './models'; import { Order, OrdersResponse } from '../orders/models'; import { OrderEntity } from 'src/db/orders'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; @Resolver(() => Auction) @@ -19,7 +19,7 @@ export class AuctionOrdersResolver extends BaseResolver(Auction) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const { id } = auction; if (!id) { return null; diff --git a/src/modules/auctions/auctions-queries.resolver.ts b/src/modules/auctions/auctions-queries.resolver.ts index 773e3eb14..0264fc0ad 100644 --- a/src/modules/auctions/auctions-queries.resolver.ts +++ b/src/modules/auctions/auctions-queries.resolver.ts @@ -6,7 +6,7 @@ import { UseGuards } from '@nestjs/common'; import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; import { AssetsProvider } from '../assets/loaders/assets.loader'; import { Account } from '../account-stats/models'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import { FiltersExpression, Sorting, Grouping } from '../common/filters/filtersTypes'; import { AuctionCustomFilter } from '../common/filters/AuctionCustomFilters'; import PageResponse from '../common/PageResponse'; @@ -68,7 +68,7 @@ export class AuctionsQueriesResolver extends BaseResolver(Auction) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [auctions, count, priceRange] = await this.auctionsGetterService.getAuctions( new QueryRequest({ limit, @@ -97,7 +97,7 @@ export class AuctionsQueriesResolver extends BaseResolver(Auction) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [auctions, count, priceRange] = await this.auctionsGetterService.getAuctionsOrderByNoBids( new QueryRequest({ limit, offset, filters, groupByOption: groupBy }), @@ -134,7 +134,7 @@ export class AuctionsQueriesResolver extends BaseResolver(Auction) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [auctions, count] = await this.auctionsGetterService.getClaimableAuctions(limit, offset, user.address, filters?.marketplaceKey); return PageResponse.mapResponse(auctions, pagination, count, offset, limit); } diff --git a/src/modules/campaigns/campaigns-queries.resolver.ts b/src/modules/campaigns/campaigns-queries.resolver.ts index 616e4f87b..d93abf991 100644 --- a/src/modules/campaigns/campaigns-queries.resolver.ts +++ b/src/modules/campaigns/campaigns-queries.resolver.ts @@ -1,7 +1,7 @@ import { Resolver, Query, Args, ResolveField, Parent } from '@nestjs/graphql'; import { BaseResolver } from '../common/base.resolver'; import { Campaign, CampaignsResponse } from './models'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { CampaignStatusEnum } from './models/CampaignStatus.enum'; import { DateUtils } from 'src/utils/date-utils'; @@ -21,7 +21,7 @@ export class CampaignsQueriesResolver extends BaseResolver(Campaign) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const campaigns = await this.campaignsService.getCampaigns(limit, offset, filters); return PageResponse.mapResponse(campaigns?.items || [], pagination, campaigns?.count || 0, offset, limit); } diff --git a/src/modules/common/filters/ConnectionArgs.ts b/src/modules/common/filters/ConnectionArgs.ts index 1b3cbbf41..b359e6673 100644 --- a/src/modules/common/filters/ConnectionArgs.ts +++ b/src/modules/common/filters/ConnectionArgs.ts @@ -36,7 +36,7 @@ function checkPagingSanity(args: ConnectionArgs): PagingMeta { const getId = (cursor: ConnectionCursor) => parseInt(fromGlobalId(cursor).id, 10); const nextId = (cursor: ConnectionCursor) => getId(cursor) + 1; -function getPagingParameters(args: ConnectionArgs) { +export function getPagingParameters(args: ConnectionArgs) { const meta = checkPagingSanity(args); switch (meta.pagingType) { @@ -81,10 +81,6 @@ export default class ConnectionArgs implements ConnectionArguments { @Max(100) @Field(() => Int, { nullable: true, description: 'Paginate last' }) public last?: number; - - pagingParams() { - return getPagingParameters(this); - } } @InputType() diff --git a/src/modules/featured/featured-collections.resolver.ts b/src/modules/featured/featured-collections.resolver.ts index da4f6fbcd..914e0affe 100644 --- a/src/modules/featured/featured-collections.resolver.ts +++ b/src/modules/featured/featured-collections.resolver.ts @@ -4,7 +4,7 @@ import { Asset, AssetsResponse } from '../assets/models'; import { GqlAdminAuthGuard } from '../auth/gql-admin.auth-guard'; import { JwtOrNativeAuthGuard } from '../auth/jwt.or.native.auth-guard'; import { BaseResolver } from '../common/base.resolver'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { Collection } from '../nftCollections/models'; import CollectionResponse from '../nftCollections/models/CollectionResponse'; @@ -29,7 +29,7 @@ export class FeaturedCollectionsResolver extends BaseResolver(Collection) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [collections, count] = await this.featuredService.getFeaturedCollections(filters, limit, offset); return PageResponse.mapResponse(collections || [], pagination, count || 0, offset, limit); } diff --git a/src/modules/featured/featured-nfts.resolver.ts b/src/modules/featured/featured-nfts.resolver.ts index a6b9b75fa..adebfc24c 100644 --- a/src/modules/featured/featured-nfts.resolver.ts +++ b/src/modules/featured/featured-nfts.resolver.ts @@ -1,7 +1,7 @@ import { Resolver, Query, Args } from '@nestjs/graphql'; import { Asset, AssetsResponse } from '../assets/models'; import { BaseResolver } from '../common/base.resolver'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { FeaturedService } from './featured.service'; @@ -16,7 +16,7 @@ export class FeaturedNftsResolver extends BaseResolver(Asset) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [assets, count] = await this.featuredNftsService.getFeaturedNfts(limit, offset); return PageResponse.mapResponse(assets || [], pagination, count || 0, offset, limit); } diff --git a/src/modules/marketplaces/marketplaces-queries.resolver.ts b/src/modules/marketplaces/marketplaces-queries.resolver.ts index 2063c72a1..2e4658f57 100644 --- a/src/modules/marketplaces/marketplaces-queries.resolver.ts +++ b/src/modules/marketplaces/marketplaces-queries.resolver.ts @@ -1,6 +1,6 @@ import { Resolver, Query, Args, ResolveField, Parent } from '@nestjs/graphql'; import { BaseResolver } from '../common/base.resolver'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { MarketplacesService } from './marketplaces.service'; import { Marketplace } from './models/Marketplace.dto'; @@ -28,7 +28,7 @@ export class MarketplacesQueriesResolver extends BaseResolver(Marketplace) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const marketplaces = await this.marketplaceService.getMarketplaces(limit, offset, filters); // todo: investigate pagination.after = undefined; diff --git a/src/modules/minters/minters-queries.resolver.ts b/src/modules/minters/minters-queries.resolver.ts index c4b297658..d6e122495 100644 --- a/src/modules/minters/minters-queries.resolver.ts +++ b/src/modules/minters/minters-queries.resolver.ts @@ -6,7 +6,7 @@ import { JwtOrNativeAuthGuard } from '../auth/jwt.or.native.auth-guard'; import { MintersService } from './minters.service'; import { GqlAdminAuthGuard } from '../auth/gql-admin.auth-guard'; import { MinterFilters } from './models/MinterFilters'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { MintersResponse } from './models/MintersResponse'; @@ -23,7 +23,7 @@ export class MintersQueriesResolver extends BaseResolver(MintersResponse) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const minters = await this.minterService.getMinters(filters); return PageResponse.mapResponse(minters || [], pagination, minters?.length || 0, offset, limit); } diff --git a/src/modules/nftCollections/collections-queries.resolver.ts b/src/modules/nftCollections/collections-queries.resolver.ts index d5c042862..65d8d7d91 100644 --- a/src/modules/nftCollections/collections-queries.resolver.ts +++ b/src/modules/nftCollections/collections-queries.resolver.ts @@ -4,7 +4,7 @@ import { Collection, CollectionAsset } from './models'; import CollectionResponse from './models/CollectionResponse'; import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; import { Account } from '../account-stats/models'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { OnSaleAssetsCountForCollectionProvider } from './loaders/onsale-assets-count.loader'; import { Address } from '@multiversx/sdk-core'; @@ -45,7 +45,7 @@ export class CollectionsQueriesResolver extends BaseResolver(Collection) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [collections, count] = await this.collectionsGetterService.getCollections(offset, limit, filters, sorting); return PageResponse.mapResponse(collections || [], pagination, count || 0, offset, limit); diff --git a/src/modules/notifications/notifications.resolver.ts b/src/modules/notifications/notifications.resolver.ts index 67e19541e..84b49d5dc 100644 --- a/src/modules/notifications/notifications.resolver.ts +++ b/src/modules/notifications/notifications.resolver.ts @@ -3,7 +3,7 @@ import { BaseResolver } from '../common/base.resolver'; import { NotificationsService } from './notifications.service'; import { NotificationsResponse, Notification } from './models'; import { connectionFromArraySlice } from 'graphql-relay'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import { UseGuards } from '@nestjs/common'; import { NotificationsFilters } from './models/Notifications.Filter'; import { JwtOrNativeAuthGuard } from '../auth/jwt.or.native.auth-guard'; @@ -25,7 +25,7 @@ export class NotificationsResolver extends BaseResolver(Notification) { pagination: ConnectionArgs, @AuthUser() user: UserAuthResult, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [notifications, count] = await this.notificationsService.getNotifications(user.address, filters?.marketplaceKey); const page = connectionFromArraySlice(notifications, pagination, { arrayLength: count, diff --git a/src/modules/offers/offers.resolver.ts b/src/modules/offers/offers.resolver.ts index 399262cba..6cc19dd00 100644 --- a/src/modules/offers/offers.resolver.ts +++ b/src/modules/offers/offers.resolver.ts @@ -5,7 +5,7 @@ import { connectionFromArraySlice } from 'graphql-relay'; import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; import { NftMarketplaceAbiService } from '../auctions'; import { Account } from '../account-stats/models'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import { UseGuards } from '@nestjs/common'; import { TransactionNode } from '../common/transaction'; import { AssetsProvider } from '../assets'; @@ -40,7 +40,7 @@ export class OffersResolver extends BaseResolver(Offer) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [offers, count] = await this.offersService.getOffers(filters, offset, limit); const page = connectionFromArraySlice(offers, pagination, { arrayLength: count, diff --git a/src/modules/orders/orders.resolver.ts b/src/modules/orders/orders.resolver.ts index 4e25a5a12..8295c8967 100644 --- a/src/modules/orders/orders.resolver.ts +++ b/src/modules/orders/orders.resolver.ts @@ -8,7 +8,7 @@ import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; import { AuctionProvider } from '../auctions'; import { Account } from '../account-stats/models'; import { FiltersExpression, Sorting } from '../common/filters/filtersTypes'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import { QueryRequest } from '../common/filters/QueryRequest'; @Resolver(() => Order) @@ -26,7 +26,7 @@ export class OrdersResolver extends BaseResolver(Order) { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ) { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [orders, count] = await this.ordersService.getOrders(new QueryRequest({ limit, offset, filters, sorting })); const page = connectionFromArraySlice(orders, pagination, { arrayLength: count, diff --git a/src/modules/owners/owners.resolver.ts b/src/modules/owners/owners.resolver.ts index 7cffcc5a1..9412c2772 100644 --- a/src/modules/owners/owners.resolver.ts +++ b/src/modules/owners/owners.resolver.ts @@ -3,7 +3,7 @@ import { Query, Resolver, Args, ResolveField, Parent } from '@nestjs/graphql'; import { OwnersService } from './owners.service'; import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; import { Account } from '../account-stats/models'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; @Resolver(() => Owner) @@ -17,7 +17,7 @@ export class OwnersResolver { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [owners, count] = await this.ownersService.getOwnersForIdentifier(filters?.identifier, offset, limit); return PageResponse.mapResponse(owners || [], pagination, count || 0, offset, limit); } diff --git a/src/modules/tags/tags.resolver.ts b/src/modules/tags/tags.resolver.ts index 97376ff7c..620b5b33b 100644 --- a/src/modules/tags/tags.resolver.ts +++ b/src/modules/tags/tags.resolver.ts @@ -2,7 +2,7 @@ import { Tag } from './models'; import { Args, Query, Resolver } from '@nestjs/graphql'; import { TagsService } from './tags.service'; import { TagsResponse } from './models/TagsResponse'; -import ConnectionArgs from '../common/filters/ConnectionArgs'; +import ConnectionArgs, { getPagingParameters } from '../common/filters/ConnectionArgs'; import PageResponse from '../common/PageResponse'; import { TagsFilter } from './models/Tags.Filter'; @@ -17,7 +17,7 @@ export class TagsResolver { @Args({ name: 'pagination', type: () => ConnectionArgs, nullable: true }) pagination: ConnectionArgs, ): Promise { - const { limit, offset } = pagination.pagingParams(); + const { limit, offset } = getPagingParameters(pagination); const [tags, count] = await this.tagsService.getTags(offset, limit, filters); return PageResponse.mapResponse(tags || [], pagination, count || 0, offset, limit);