aboutsummaryrefslogtreecommitdiff
path: root/src/database.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-07-02 16:12:23 -0500
committermat <github@matdoes.dev>2022-07-02 16:12:23 -0500
commit4c0649fcf401bf291377a6ab42541b4b567922de (patch)
treeff43fe9df5d2da554e197791c259fd758fcb2caa /src/database.ts
parentf6504b6d78547052f5686409724ded181e3d1ded (diff)
downloadskyblock-api-4c0649fcf401bf291377a6ab42541b4b567922de.tar.gz
skyblock-api-4c0649fcf401bf291377a6ab42541b4b567922de.tar.bz2
skyblock-api-4c0649fcf401bf291377a6ab42541b4b567922de.zip
don't transfer lore
Diffstat (limited to 'src/database.ts')
-rw-r--r--src/database.ts41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/database.ts b/src/database.ts
index d513256..66edeff 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -144,12 +144,31 @@ export interface SimpleAuctionSchema {
/** The lore of the item. */
lore: string
}
+/** Same as SimpleAuctionSchema except without lore. */
+export interface SimplerAuctionSchema {
+ coins: number
+ /**
+ * The timestamp as **seconds** since epoch. It's in seconds instead of ms
+ * since we don't need to be super exact and so it's shorter.
+ */
+ ts: number
+ /** Whether the auction was successfully bought or simply expired. */
+ s: boolean
+ bin: boolean
+}
+
export interface ItemAuctionsSchema {
/** The id of the item */
id: string
sbId: string
auctions: SimpleAuctionSchema[]
}
+export interface SimplerItemAuctionsSchema {
+ /** The id of the item */
+ id: string
+ sbId: string
+ auctions: SimplerAuctionSchema[]
+}
export interface ItemAuctionsSchemaBson {
/** The id of the item */
_id: string
@@ -1129,6 +1148,17 @@ function toItemAuctionsSchema(i: ItemAuctionsSchemaBson): ItemAuctionsSchema {
}),
}
}
+function toSimplerItemAuctionsSchema(i: ItemAuctionsSchema): SimplerItemAuctionsSchema {
+ return {
+ id: i.id,
+ sbId: i.sbId,
+ auctions: i.auctions.map((a: any) => {
+ if ('lore' in a)
+ delete a.lore
+ return a
+ }),
+ }
+}
function toItemAuctionsSchemaBson(i: ItemAuctionsSchema): ItemAuctionsSchemaBson {
return {
@@ -1148,18 +1178,21 @@ function toItemAuctionsSchemaBson(i: ItemAuctionsSchema): ItemAuctionsSchemaBson
}
/** Fetch all the Item Auctions for the item ids in the given array. */
-export async function fetchItemsAuctions(itemIds: string[]): Promise<ItemAuctionsSchema[]> {
+export async function fetchItemsAuctions<Lore extends boolean = false>(itemIds: string[], lore: Lore): Promise<(Lore extends true ? ItemAuctionsSchema : SimplerItemAuctionsSchema)[]> {
const auctions = await itemAuctionsCollection?.find({
_id: { $in: itemIds }
}).sort('oldestDate', -1).toArray()
- return auctions.map(toItemAuctionsSchema)
+ let a = auctions.map(toItemAuctionsSchema)
+ if (!lore)
+ return a.map(toSimplerItemAuctionsSchema) as any
+ return a
}
/** Fetch all the Item Auctions for the item ids in the given array. */
-export async function fetchPaginatedItemsAuctions(skip: number, limit: number): Promise<ItemAuctionsSchema[]> {
+export async function fetchPaginatedItemsAuctions(skip: number, limit: number): Promise<SimplerItemAuctionsSchema[]> {
const auctions = await itemAuctionsCollection?.find({}).sort('oldestDate', -1).skip(skip).limit(limit).toArray()
- return auctions.map(toItemAuctionsSchema)
+ return auctions.map(toItemAuctionsSchema).map(toSimplerItemAuctionsSchema)
}
export async function updateItemAuction(auction: ItemAuctionsSchema) {