From 06071107fd3e2d7cd697a97844fb4520fef55fe0 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 1 Jul 2022 18:06:03 -0500 Subject: Pagination --- src/cleaners/skyblock/auctions.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/cleaners') diff --git a/src/cleaners/skyblock/auctions.ts b/src/cleaners/skyblock/auctions.ts index 83b77a8..bec922c 100644 --- a/src/cleaners/skyblock/auctions.ts +++ b/src/cleaners/skyblock/auctions.ts @@ -3,6 +3,11 @@ import { cleanInventory, Item } from './inventory.js' import * as cached from '../../hypixelCached.js' import { CleanPlayer } from '../player.js' +export interface Auctions { + auctions: Auction[] + pages: number +} + export interface Auction { id: string sellerUuid: string @@ -16,19 +21,22 @@ export interface Auction { } -export async function cleanAuctions(data: typedHypixelApi.SkyBlockRequestAuctionResponse): Promise { +export async function cleanAuctions(data: typedHypixelApi.SkyBlockRequestAuctionResponse, page: number): Promise { const auctionPromises: Promise[] = [] - for (const auction of data.auctions) { + + let rawAuctions = data.auctions + // sort by newer first + rawAuctions.sort((a, b) => b.start - a.start) + + rawAuctions = rawAuctions.slice(page * 10, page * 10 + 10) + + for (const auction of rawAuctions) { auctionPromises.push(cleanAuction(auction)) } const auctions = await Promise.all(auctionPromises) - // sort by newer first - auctions.sort((a, b) => b.creationTimestamp - a.creationTimestamp) - - return auctions - + return { auctions, pages: Math.ceil(rawAuctions.length / 10) } } async function cleanAuction(auction: typedHypixelApi.SkyBlockRequestAuctionResponse['auctions'][number]): Promise { -- cgit