-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert rankedpvp.ts to working state
Signed-off-by: Phrosfire <[email protected]>
- Loading branch information
Showing
1 changed file
with
8 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
import { RankedDivisions } from "@/drizzle/constants"; | ||
import { gte, desc } from "drizzle-orm"; | ||
import { drizzleDB } from "@/server/db"; | ||
import { userData } from "@/drizzle/schema"; | ||
|
||
export const getPvpRank = async ( | ||
userId: string, | ||
rankedLp: number | ||
): Promise<string> => { | ||
try { | ||
const topSannins = await drizzleDB | ||
.select({ userId: userData.userId }) | ||
.from(userData) | ||
.where(gte(userData.rankedLp, 900)) | ||
.orderBy(desc(userData.rankedLp)) | ||
.limit(10); | ||
|
||
// Check if the user is in the top 10 | ||
const isTopSannin = topSannins.some(player => player.userId === userId); | ||
|
||
if (isTopSannin) return "Sannin"; // Only top 10 get Sannin | ||
if (rankedLp >= 900) return "Legend"; // Others default to Legend | ||
|
||
// Find the highest rank the user qualifies for | ||
return ( | ||
RankedDivisions.slice() | ||
.reverse() | ||
.find(rank => rankedLp >= rank.rankedLp)?.name || "Wood" | ||
); | ||
} catch (error) { | ||
console.error("Error fetching PvP rank:", error); | ||
return "Wood"; // Default to lowest rank if an error occurs | ||
} | ||
// Get PvP Rank by LP | ||
export const getPvpRank = (rating: number): string => { | ||
return ( | ||
RankedDivisions | ||
.slice() | ||
.reverse() | ||
.find(rank => rating >= rank.rankedLp)?.name || "Wood" | ||
); | ||
}; |