feat : add profile page
This commit is contained in:
@@ -69,6 +69,29 @@ export async function getXpLeaderboardPage(
|
||||
return buildXpLeaderboard(rows, requestedPage, searchQuery);
|
||||
}
|
||||
|
||||
export async function getMemberXpStats(userId: string) {
|
||||
const database = getLeaderboardDatabase();
|
||||
const [sourceRows, leaderboard] = await Promise.all([
|
||||
database
|
||||
.select({
|
||||
level: userLevels.level,
|
||||
totalXp: userLevels.xp,
|
||||
})
|
||||
.from(userLevels)
|
||||
.where(eq(userLevels.userId, userId))
|
||||
.limit(1),
|
||||
getXpLeaderboardPage(1, userId),
|
||||
]);
|
||||
const rankedRow = leaderboard.rows.find((row) => row.userId === userId);
|
||||
const sourceRow = sourceRows[0];
|
||||
|
||||
return {
|
||||
level: sourceRow?.level ?? 0,
|
||||
totalXp: sourceRow?.totalXp ?? "0",
|
||||
rank: rankedRow?.rank ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getVoiceLeaderboardPage(
|
||||
currentChannelIds: string[],
|
||||
requestedPage: number,
|
||||
@@ -109,6 +132,24 @@ export async function getVoiceLeaderboardPage(
|
||||
);
|
||||
}
|
||||
|
||||
export async function getMemberVoiceStats(
|
||||
userId: string,
|
||||
currentChannelIds: string[],
|
||||
) {
|
||||
const leaderboard = await getVoiceLeaderboardPage(
|
||||
currentChannelIds,
|
||||
1,
|
||||
undefined,
|
||||
userId,
|
||||
);
|
||||
const rankedRow = leaderboard.rows.find((row) => row.userId === userId);
|
||||
|
||||
return {
|
||||
totalSeconds: rankedRow?.totalSeconds ?? "0",
|
||||
rank: rankedRow?.rank ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getLeaderboardDatabaseReadOnlyStatus() {
|
||||
const result = await getLeaderboardDatabase().execute<{
|
||||
transaction_read_only: string;
|
||||
|
||||
Reference in New Issue
Block a user