added clear lamps and fixed score grid size problems
This commit is contained in:
@ -1,11 +1,150 @@
|
||||
"use server";
|
||||
|
||||
import { artemis } from "@/lib/prisma";
|
||||
import { chuni_score_best } from "@/prisma/schemas/artemis/generated/artemis";
|
||||
import type * as Prisma from "@prisma/client";
|
||||
|
||||
type ChuniScorePlaylog = Prisma.PrismaClient;
|
||||
type ChuniStaticMusic = Prisma.PrismaClient;
|
||||
|
||||
export async function getSongsWithTitles(userId: number) {
|
||||
try {
|
||||
const songs: ChuniScorePlaylog[] =
|
||||
await artemis.chuni_score_playlog.findMany({
|
||||
where: {
|
||||
user: userId,
|
||||
},
|
||||
orderBy: {
|
||||
userPlayDate: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
maxCombo: true,
|
||||
userPlayDate: true,
|
||||
isFullCombo: true,
|
||||
playerRating: true,
|
||||
isAllJustice: true,
|
||||
score: true,
|
||||
judgeHeaven: true,
|
||||
judgeGuilty: true,
|
||||
judgeJustice: true,
|
||||
judgeAttack: true,
|
||||
judgeCritical: true,
|
||||
isClear: true,
|
||||
skillId: true,
|
||||
skillEffect: true,
|
||||
skillLevel: true,
|
||||
isNewRecord: true,
|
||||
musicId: true,
|
||||
level: true,
|
||||
rateAir: true,
|
||||
rateHold: true,
|
||||
rateFlick: true,
|
||||
rateSlide: true,
|
||||
rateTap: true,
|
||||
romVersion: true,
|
||||
eventId: true,
|
||||
characterId: true,
|
||||
charaIllustId: true,
|
||||
track: true,
|
||||
isContinue: true,
|
||||
isFreeToPlay: true,
|
||||
playKind: true,
|
||||
playDate: true,
|
||||
orderId: true,
|
||||
sortNumber: true,
|
||||
user: true,
|
||||
placeId: true,
|
||||
ticketId: true,
|
||||
},
|
||||
});
|
||||
|
||||
const chuniScorePlaylogMusicId = songs
|
||||
.map((song) => song.musicId)
|
||||
.filter((id): id is number => id !== null);
|
||||
|
||||
const staticMusicInfo: ChuniStaticMusic[] =
|
||||
await artemis.chuni_static_music.findMany({
|
||||
where: {
|
||||
songId: {
|
||||
in: chuniScorePlaylogMusicId,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
songId: true,
|
||||
title: true,
|
||||
artist: true,
|
||||
chartId: true,
|
||||
level: true,
|
||||
genre: true,
|
||||
worldsEndTag: true,
|
||||
jacketPath: true,
|
||||
},
|
||||
});
|
||||
|
||||
const chuniScoreBest: chuni_score_best[] =
|
||||
await artemis.chuni_score_best.findMany({
|
||||
where: {
|
||||
musicId: {
|
||||
in: chuniScorePlaylogMusicId,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
user: true,
|
||||
musicId: true,
|
||||
level: true,
|
||||
playCount: true,
|
||||
scoreMax: true,
|
||||
resRequestCount: true,
|
||||
resAcceptCount: true,
|
||||
resSuccessCount: true,
|
||||
missCount: true,
|
||||
maxComboCount: true,
|
||||
isFullCombo: true,
|
||||
isAllJustice: true,
|
||||
isSuccess: true,
|
||||
fullChain: true,
|
||||
maxChain: true,
|
||||
scoreRank: true,
|
||||
isLock: true,
|
||||
ext1: true,
|
||||
theoryCount: true,
|
||||
},
|
||||
});
|
||||
|
||||
const songsWithTitles = songs.map((song) => {
|
||||
const staticInfo = staticMusicInfo.find(
|
||||
(chuniStaticMusic) =>
|
||||
chuniStaticMusic.songId === song.musicId &&
|
||||
chuniStaticMusic.chartId === song.level,
|
||||
);
|
||||
|
||||
const bestScore = chuniScoreBest.find(
|
||||
(score) => score.musicId === song.musicId,
|
||||
);
|
||||
|
||||
return {
|
||||
...song,
|
||||
title: staticInfo?.title || "Unknown Title",
|
||||
artist: staticInfo?.artist || "Unknown Artist",
|
||||
genre: staticInfo?.genre || "Unknown Genre",
|
||||
chartId: staticInfo?.chartId || "Unknown chartId",
|
||||
level: staticInfo?.level || "Unknown Level",
|
||||
chartlevel: song.level || "Unknown Level",
|
||||
playCount: bestScore?.playCount || 0,
|
||||
isSuccess: bestScore?.isSuccess || 0,
|
||||
jacketPath: staticInfo?.jacketPath || "",
|
||||
};
|
||||
});
|
||||
|
||||
return songsWithTitles;
|
||||
} catch (error) {
|
||||
console.error("Error fetching songs with titles:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function searchSongWithTitle(
|
||||
userId: number,
|
||||
searchQuery: string = "",
|
||||
@ -39,32 +178,41 @@ export async function searchSongWithTitle(
|
||||
},
|
||||
},
|
||||
select: {
|
||||
songId: true,
|
||||
title: true,
|
||||
},
|
||||
});
|
||||
|
||||
const playCounts = await artemis.chuni_score_playlog.groupBy({
|
||||
by: ["musicId"],
|
||||
_count: {
|
||||
musicId: true,
|
||||
},
|
||||
where: {
|
||||
user: userId,
|
||||
musicId: {
|
||||
in: chuniScorePlaylogMusicId,
|
||||
const chuniScoreBest: chuni_score_best[] =
|
||||
await artemis.chuni_score_best.findMany({
|
||||
where: {
|
||||
musicId: {
|
||||
in: chuniScorePlaylogMusicId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const playCountMap = playCounts.reduce(
|
||||
(map, item) => {
|
||||
if (item.musicId !== null) {
|
||||
map[item.musicId] = item._count.musicId;
|
||||
}
|
||||
return map;
|
||||
},
|
||||
{} as Record<number, number>,
|
||||
);
|
||||
select: {
|
||||
id: true,
|
||||
user: true,
|
||||
musicId: true,
|
||||
level: true,
|
||||
playCount: true,
|
||||
scoreMax: true,
|
||||
resRequestCount: true,
|
||||
resAcceptCount: true,
|
||||
resSuccessCount: true,
|
||||
missCount: true,
|
||||
maxComboCount: true,
|
||||
isFullCombo: true,
|
||||
isAllJustice: true,
|
||||
isSuccess: true,
|
||||
fullChain: true,
|
||||
maxChain: true,
|
||||
scoreRank: true,
|
||||
isLock: true,
|
||||
ext1: true,
|
||||
theoryCount: true,
|
||||
},
|
||||
});
|
||||
|
||||
const songsWithTitles = songs.map((song) => {
|
||||
const staticInfo = staticMusicInfo.find(
|
||||
@ -73,9 +221,14 @@ export async function searchSongWithTitle(
|
||||
chuniStaticMusic.chartId === song.level,
|
||||
);
|
||||
|
||||
const bestScore = chuniScoreBest.find(
|
||||
(score) => score.musicId === song.musicId,
|
||||
);
|
||||
|
||||
return {
|
||||
...song,
|
||||
title: staticInfo?.title || "Unknown Title",
|
||||
playCount: bestScore?.playCount || 0,
|
||||
};
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user