aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-17 20:59:52 -0500
committermat <github@matdoes.dev>2022-05-17 20:59:52 -0500
commit667b2d08638959d11bc2fbfa6e2b40b0e9834d6d (patch)
tree6868fe7848e2d57e32c3bf0991a69ef6fc3b8c00 /src
parentb577c9ace72b39daeff8e5c4278dba1230521625 (diff)
downloadskyblock-api-667b2d08638959d11bc2fbfa6e2b40b0e9834d6d.tar.gz
skyblock-api-667b2d08638959d11bc2fbfa6e2b40b0e9834d6d.tar.bz2
skyblock-api-667b2d08638959d11bc2fbfa6e2b40b0e9834d6d.zip
add oldestDate field
Diffstat (limited to 'src')
-rw-r--r--src/database.ts7
-rw-r--r--src/hypixel.ts2
2 files changed, 6 insertions, 3 deletions
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<DatabaseMemberLeaderboardItem>
@@ -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)