forked from syntaxbullet/AuroraBot-discord
feat(dashboard): expand stats & remove admin token auth
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||
import { users, transactions, moderationCases, inventory, type User } from "@db/schema";
|
||||
import { users, transactions, moderationCases, inventory, lootdrops, type User } from "@db/schema";
|
||||
import { desc, sql, gte } from "drizzle-orm";
|
||||
import type { RecentEvent, ActivityData } from "./dashboard.types";
|
||||
import { TransactionType } from "@shared/lib/constants";
|
||||
@@ -201,6 +201,44 @@ export const dashboardService = {
|
||||
|
||||
return activity;
|
||||
},
|
||||
/**
|
||||
* Get active lootdrops
|
||||
*/
|
||||
getActiveLootdrops: async () => {
|
||||
const activeDrops = await DrizzleClient.query.lootdrops.findMany({
|
||||
where: (lootdrops, { isNull }) => isNull(lootdrops.claimedBy),
|
||||
limit: 1,
|
||||
orderBy: desc(lootdrops.createdAt)
|
||||
});
|
||||
|
||||
return activeDrops;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get leaderboards (Top 3 Levels and Wealth)
|
||||
*/
|
||||
getLeaderboards: async () => {
|
||||
const topLevels = await DrizzleClient.select({
|
||||
username: users.username,
|
||||
level: users.level,
|
||||
})
|
||||
.from(users)
|
||||
.orderBy(desc(users.level))
|
||||
.limit(3);
|
||||
|
||||
const topWealth = await DrizzleClient.select({
|
||||
username: users.username,
|
||||
balance: users.balance,
|
||||
})
|
||||
.from(users)
|
||||
.orderBy(desc(users.balance))
|
||||
.limit(3);
|
||||
|
||||
return {
|
||||
topLevels,
|
||||
topWealth: topWealth.map(u => ({ ...u, balance: (u.balance || 0n).toString() }))
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user