2024-08-14 15:52:19 +00:00
|
|
|
"use server";
|
|
|
|
import { getAuth } from "@/auth/queries/getauth";
|
|
|
|
import { supportedVersionNumber } from "@/lib/helpers";
|
|
|
|
import { artemis } from "@/lib/prisma";
|
|
|
|
|
2024-08-15 02:27:17 +00:00
|
|
|
export async function getUserRatingBaseList() {
|
2024-08-14 15:52:19 +00:00
|
|
|
const { user } = await getAuth();
|
|
|
|
|
|
|
|
if (!user || !user.accessCode) {
|
|
|
|
throw new Error("User is not authenticated or accessCode is missing");
|
|
|
|
}
|
|
|
|
|
2024-08-15 02:27:17 +00:00
|
|
|
try {
|
|
|
|
// fuck prisma sometimes man
|
|
|
|
const results = await artemis.$queryRaw<any[]>`
|
|
|
|
SELECT
|
|
|
|
cpr.score,
|
|
|
|
csm.chartId,
|
|
|
|
csm.title,
|
|
|
|
csm.level,
|
|
|
|
csm.genre,
|
|
|
|
csm.jacketPath,
|
|
|
|
csm.artist,
|
|
|
|
'Increase' AS rating_change,
|
|
|
|
CASE
|
|
|
|
WHEN cpr.score >= 1009000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 215
|
|
|
|
WHEN cpr.score >= 1007500 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 200 + (cpr.score - 1007500) / 100
|
|
|
|
WHEN cpr.score >= 1005000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 150 + (cpr.score - 1005000) / 50
|
|
|
|
WHEN cpr.score >= 1000000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + 100 + (cpr.score - 1000000) / 100
|
|
|
|
WHEN cpr.score >= 975000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 + (cpr.score - 975000) / 250
|
|
|
|
WHEN cpr.score >= 925000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 - 300 + (cpr.score - 925000) * 3 / 500
|
|
|
|
WHEN cpr.score >= 900000 THEN CAST(csm.level AS DECIMAL(10,2)) * 100 - 500 + (cpr.score - 900000) * 4 / 500
|
|
|
|
WHEN cpr.score >= 800000 THEN ((CAST(csm.level AS DECIMAL(10,2)) * 100 - 500) / 2 + (cpr.score - 800000) * ((CAST(csm.level AS DECIMAL(10,2)) - 500) / 2) / 100000)
|
|
|
|
ELSE 0
|
|
|
|
END AS rating
|
|
|
|
FROM
|
|
|
|
chuni_profile_rating cpr
|
|
|
|
JOIN
|
|
|
|
chuni_static_music csm ON cpr.musicId = csm.songId AND cpr.difficultId = csm.chartId AND cpr.version = csm.version
|
|
|
|
WHERE
|
|
|
|
cpr.user = ${user.UserId} AND cpr.version = ${supportedVersionNumber} AND cpr.type = 'userRatingBaseList'
|
|
|
|
ORDER BY
|
|
|
|
cpr.index ASC
|
|
|
|
`;
|
2024-08-14 15:52:19 +00:00
|
|
|
|
2024-08-15 02:27:17 +00:00
|
|
|
// Return results
|
|
|
|
return results;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching songs with titles:", error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|