cleanup
This commit is contained in:
@ -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: {
|
||||||
|
@ -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) =>
|
||||||
|
Reference in New Issue
Block a user