aboutsummaryrefslogtreecommitdiff
path: root/src/database.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-15 22:37:22 -0500
committermat <github@matdoes.dev>2022-05-15 22:37:22 -0500
commita206dee8301e5a8723daab819f175d7ab01f9029 (patch)
tree303fc991d9b3dfd67e1c4ebc2249401d01074658 /src/database.ts
parent74ccbaef865f328283f91533b9c26daed6cff006 (diff)
downloadskyblock-api-a206dee8301e5a8723daab819f175d7ab01f9029.tar.gz
skyblock-api-a206dee8301e5a8723daab819f175d7ab01f9029.tar.bz2
skyblock-api-a206dee8301e5a8723daab819f175d7ab01f9029.zip
add very basic auctionprices endpoint
Diffstat (limited to 'src/database.ts')
-rw-r--r--src/database.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/database.ts b/src/database.ts
index 04b3825..8f63d97 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -17,6 +17,7 @@ import { debug } from './index.js'
import Queue from 'queue-promise'
import { RANK_COLORS } from './cleaners/rank.js'
import { cleanItemId } from './cleaners/skyblock/itemId.js'
+import { periodicallyFetchRecentlyEndedAuctions } from './hypixel.js'
// don't update the user for 3 minutes
const recentlyUpdated = new NodeCache({
@@ -116,10 +117,30 @@ export interface AccountSchema {
customization?: AccountCustomization
}
+export interface SimpleAuctionSchema {
+ /** The UUID of the auction so we can look it up later. */
+ id: string
+ 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 bought or simply expired. */
+ success: boolean
+ bin: boolean
+}
+export interface ItemAuctionsSchema {
+ /** The id of the item */
+ _id: string
+ auctions: SimpleAuctionSchema[]
+}
+
let memberLeaderboardsCollection: Collection<DatabaseMemberLeaderboardItem>
let profileLeaderboardsCollection: Collection<DatabaseProfileLeaderboardItem>
let sessionsCollection: Collection<SessionSchema>
let accountsCollection: Collection<AccountSchema>
+let itemAuctionsCollection: Collection<ItemAuctionsSchema>
const leaderboardInfos: { [leaderboardName: string]: string } = {
@@ -142,6 +163,10 @@ async function connect(): Promise<void> {
profileLeaderboardsCollection = database.collection('profile-leaderboards')
sessionsCollection = database.collection('sessions')
accountsCollection = database.collection('accounts')
+ itemAuctionsCollection = database.collection('item-auctions')
+
+ periodicallyFetchRecentlyEndedAuctions()
+
console.log('Connected to database :)')
}
@@ -1064,6 +1089,28 @@ export async function updateAccount(discordId: string, schema: AccountSchema) {
}, { $set: schema }, { upsert: true })
}
+/** Fetch all the Item Auctions for the item ids in the given array. */
+export async function fetchItemsAuctions(itemIds: string[]): Promise<ItemAuctionsSchema[]> {
+ const auctions = await itemAuctionsCollection?.find({
+ _id: { $in: itemIds }
+ }).toArray()
+ return auctions
+}
+
+
+/** 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()
+ return auctions
+}
+
+export async function updateItemAuction(auction: ItemAuctionsSchema) {
+ await itemAuctionsCollection?.updateOne({
+ _id: auction._id,
+ }, { $set: auction }, { upsert: true })
+}
+
+
export async function fetchServerStatus() {
return await database.admin().serverStatus()
}