From 667b2d08638959d11bc2fbfa6e2b40b0e9834d6d Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 17 May 2022 20:59:52 -0500 Subject: add oldestDate field --- src/database.ts | 7 +++++-- src/hypixel.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/database.ts b/src/database.ts index f3b8175..2392332 100644 --- a/src/database.ts +++ b/src/database.ts @@ -152,6 +152,8 @@ export interface ItemAuctionsSchemaBson { /** The id of the item */ _id: string auctions: SimpleAuctionSchemaBson[] + /** This is here so it can be indexed by Mongo, it can easily be figured out by getting the first item in auctions */ + oldestDate: number } let memberLeaderboardsCollection: Collection @@ -1111,7 +1113,7 @@ export async function updateAccount(discordId: string, schema: AccountSchema) { }, { $set: schema }, { upsert: true }) } -function toItemAuctionsSchema(i: ItemAuctionsSchemaBson) { +function toItemAuctionsSchema(i: ItemAuctionsSchemaBson): ItemAuctionsSchema { return { id: i._id, auctions: i.auctions.map(a => { @@ -1123,7 +1125,7 @@ function toItemAuctionsSchema(i: ItemAuctionsSchemaBson) { } } -function toItemAuctionsSchemaBson(i: ItemAuctionsSchema) { +function toItemAuctionsSchemaBson(i: ItemAuctionsSchema): ItemAuctionsSchemaBson { return { _id: i.id, auctions: i.auctions.map(a => { @@ -1132,6 +1134,7 @@ function toItemAuctionsSchemaBson(i: ItemAuctionsSchema) { id: createUuid(a.id) } }), + oldestDate: i.auctions[0]?.ts ?? 0 } } diff --git a/src/hypixel.ts b/src/hypixel.ts index a2a8749..a29a7b1 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -416,7 +416,7 @@ export async function periodicallyFetchRecentlyEndedAuctions() { bin: auction.bin, } // make sure the auction isn't already in there - if (auctions.find((a) => a.id === simpleAuction.id)) { + if (!auctions.find((a) => a.id === simpleAuction.id)) { auctions.push(simpleAuction) // keep only the last 100 items if (auctions.length > 100) -- cgit