This commit is contained in:
Polaris
2024-08-26 11:15:36 -04:00
parent ca85649057
commit 7841fe8ff9
2 changed files with 10 additions and 14 deletions

View File

@ -1,5 +1,6 @@
"use server"; "use server";
import { getAuth } from "@/auth/queries/getauth";
import { artemis, daphnis } from "@/lib/prisma"; import { artemis, daphnis } from "@/lib/prisma";
import type * as Prisma from "@prisma/client"; import type * as Prisma from "@prisma/client";
@ -10,12 +11,14 @@ type LinkSharingToken = {
playlogId: number; playlogId: number;
}; };
export async function getSongsWithTitles(userId: number) { export async function getSharedSong() {
const { user } = await getAuth();
try { try {
const songs: ChuniScorePlaylog[] = const songs: ChuniScorePlaylog[] =
await artemis.chuni_score_playlog.findMany({ await artemis.chuni_score_playlog.findMany({
where: { where: {
user: userId, user: user?.UserId,
}, },
orderBy: { orderBy: {
userPlayDate: "desc", userPlayDate: "desc",
@ -91,7 +94,7 @@ export async function getSongsWithTitles(userId: number) {
musicId: true, musicId: true,
}, },
where: { where: {
user: userId, user: user?.UserId,
musicId: { musicId: {
in: chuniScorePlaylogMusicId, in: chuniScorePlaylogMusicId,
}, },
@ -135,7 +138,7 @@ export async function getSongsWithTitles(userId: number) {
} }
} }
export async function generatePlaylogId(playlogid: number) { export async function getPlaylogId(playlogid: number) {
try { try {
const tokens = (await daphnis.linkSharingToken.findMany({ const tokens = (await daphnis.linkSharingToken.findMany({
where: { where: {

View File

@ -5,7 +5,7 @@ import {
type chuni_score_playlog, type chuni_score_playlog,
chuni_static_music, chuni_static_music,
} from "@/prisma/schemas/artemis/generated/artemis"; } from "@/prisma/schemas/artemis/generated/artemis";
import { generatePlaylogId, getSongsWithTitles } from "./actions"; import { getPlaylogId, getSharedSong } from "./actions";
type chunithm = chuni_score_playlog & type chunithm = chuni_score_playlog &
chuni_static_music & { playCount: number }; chuni_static_music & { playCount: number };
@ -25,17 +25,10 @@ export default async function Share({
return <p>{tokenResult.error}</p>; return <p>{tokenResult.error}</p>;
} }
const { user } = await getAuth();
if (!user?.UserId) {
return <p>Error: No user ID found.</p>;
}
const userId = user?.UserId;
const playlogId = parseInt(id); const playlogId = parseInt(id);
const songsData = await getSongsWithTitles(userId); const songsData = await getSharedSong();
const playlogIds = await generatePlaylogId(playlogId); const playlogIds = await getPlaylogId(playlogId);
// Filter songsData to match the playlogIds // Filter songsData to match the playlogIds
const chunithm: chunithm[] = songsData.filter((song) => const chunithm: chunithm[] = songsData.filter((song) =>