diff options
author | mat <github@matdoes.dev> | 2022-07-01 18:06:03 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-07-01 18:06:03 -0500 |
commit | 06071107fd3e2d7cd697a97844fb4520fef55fe0 (patch) | |
tree | be056af8e631329d17e2ee0311c9eb88835561c5 /src/cleaners/skyblock | |
parent | 55a62be03612553160779d87ea55dce05fc57e8e (diff) | |
download | skyblock-api-06071107fd3e2d7cd697a97844fb4520fef55fe0.tar.gz skyblock-api-06071107fd3e2d7cd697a97844fb4520fef55fe0.tar.bz2 skyblock-api-06071107fd3e2d7cd697a97844fb4520fef55fe0.zip |
Pagination
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/auctions.ts | 22 |
1 files changed, 15 insertions, 7 deletions
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<Auction[]> { +export async function cleanAuctions(data: typedHypixelApi.SkyBlockRequestAuctionResponse, page: number): Promise<Auctions> { const auctionPromises: Promise<Auction>[] = [] - 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<Auction> { |