feat: (ui) leaderboards
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||
import { users, transactions, moderationCases, inventory, lootdrops, type User } from "@db/schema";
|
||||
import { desc, sql, gte } from "drizzle-orm";
|
||||
import { users, transactions, moderationCases, inventory, lootdrops, items, type User } from "@db/schema";
|
||||
import { desc, sql, gte, eq } from "drizzle-orm";
|
||||
import type { RecentEvent, ActivityData } from "./dashboard.types";
|
||||
import { TransactionType } from "@shared/lib/constants";
|
||||
|
||||
@@ -224,7 +224,7 @@ export const dashboardService = {
|
||||
})
|
||||
.from(users)
|
||||
.orderBy(desc(users.level))
|
||||
.limit(3);
|
||||
.limit(10);
|
||||
|
||||
const topWealth = await DrizzleClient.select({
|
||||
username: users.username,
|
||||
@@ -232,11 +232,25 @@ export const dashboardService = {
|
||||
})
|
||||
.from(users)
|
||||
.orderBy(desc(users.balance))
|
||||
.limit(3);
|
||||
.limit(10);
|
||||
|
||||
|
||||
|
||||
const topNetWorth = await DrizzleClient.select({
|
||||
username: users.username,
|
||||
netWorth: sql<bigint>`${users.balance} + COALESCE(SUM(${items.price} * ${inventory.quantity}), 0)`.as('net_worth')
|
||||
})
|
||||
.from(users)
|
||||
.leftJoin(inventory, eq(users.id, inventory.userId))
|
||||
.leftJoin(items, eq(inventory.itemId, items.id))
|
||||
.groupBy(users.id, users.username, users.balance)
|
||||
.orderBy(desc(sql`net_worth`))
|
||||
.limit(10);
|
||||
|
||||
return {
|
||||
topLevels,
|
||||
topWealth: topWealth.map(u => ({ ...u, balance: (u.balance || 0n).toString() }))
|
||||
topWealth: topWealth.map(u => ({ ...u, balance: (u.balance || 0n).toString() })),
|
||||
topNetWorth: topNetWorth.map(u => ({ ...u, netWorth: (u.netWorth || 0n).toString() }))
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user