From 31b2b2bcc411c6bffb925eaff50731f9aefb5a82 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 17 May 2022 21:10:38 -0500 Subject: Sort auctions by most sold --- src/database.ts | 5 +++-- src/hypixel.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/database.ts b/src/database.ts index 2392332..d0ad04b 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1142,14 +1142,14 @@ function toItemAuctionsSchemaBson(i: ItemAuctionsSchema): ItemAuctionsSchemaBson export async function fetchItemsAuctions(itemIds: string[]): Promise { const auctions = await itemAuctionsCollection?.find({ _id: { $in: itemIds } - }).toArray() + }).sort('oldestDate', -1).toArray() return auctions.map(toItemAuctionsSchema) } /** Fetch all the Item Auctions for the item ids in the given array. */ export async function fetchPaginatedItemsAuctions(skip: number, limit: number): Promise { - const auctions = await itemAuctionsCollection?.find({}).skip(skip).limit(limit).toArray() + const auctions = await itemAuctionsCollection?.find({}).sort('oldestDate', -1).skip(skip).limit(limit).toArray() return auctions.map(toItemAuctionsSchema) } @@ -1165,6 +1165,7 @@ export async function updateItemAuction(auction: ItemAuctionsSchema) { export async function fetchItemsAuctionsIds(): Promise { if (!itemAuctionsCollection) return undefined const docs = await itemAuctionsCollection?.aggregate([ + { $sort: { oldestDate: -1 } }, // this removes everything except the _id { $project: { _id: true } } ]).toArray() diff --git a/src/hypixel.ts b/src/hypixel.ts index a29a7b1..2e0c1bc 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -500,7 +500,7 @@ async function fetchAuctionItemsUncached() { // if the item in the database isn't in the items api, just set the name to the id for (const item of auctionItemIds) if (!idsToNames.has(item)) - idsToNames.set(item, item) + idsToNames.set(item, item.toLowerCase().replace(/^./, item[0].toUpperCase()).replace(/_/g, ' ')) return idsToNames } -- cgit