Skip to content

Commit

Permalink
revert rankedpvp.ts to working state
Browse files Browse the repository at this point in the history
Signed-off-by: Phrosfire <[email protected]>
  • Loading branch information
Phrosfire authored Mar 9, 2025
1 parent 1439070 commit c697695
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions app/src/utils/rankedpvp.ts
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"
);
};

0 comments on commit c697695

Please sign in to comment.