aboutsummaryrefslogtreecommitdiff
path: root/src/database.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-17 21:10:38 -0500
committermat <github@matdoes.dev>2022-05-17 21:10:38 -0500
commit31b2b2bcc411c6bffb925eaff50731f9aefb5a82 (patch)
treefca920a7277b11bec6b56d1c7063bb15ddf94584 /src/database.ts
parent667b2d08638959d11bc2fbfa6e2b40b0e9834d6d (diff)
downloadskyblock-api-31b2b2bcc411c6bffb925eaff50731f9aefb5a82.tar.gz
skyblock-api-31b2b2bcc411c6bffb925eaff50731f9aefb5a82.tar.bz2
skyblock-api-31b2b2bcc411c6bffb925eaff50731f9aefb5a82.zip
Sort auctions by most sold
Diffstat (limited to 'src/database.ts')
-rw-r--r--src/database.ts5
1 files changed, 3 insertions, 2 deletions
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<ItemAuctionsSchema[]> {
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<ItemAuctionsSchema[]> {
- 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<string[] | undefined> {
if (!itemAuctionsCollection) return undefined
const docs = await itemAuctionsCollection?.aggregate([
+ { $sort: { oldestDate: -1 } },
// this removes everything except the _id
{ $project: { _id: true } }
]).toArray()