diff --git a/app/(sharing)/[token]/[id]/page.tsx b/app/(sharing)/[token]/[id]/page.tsx
index a3405e9..20dbcfa 100644
--- a/app/(sharing)/[token]/[id]/page.tsx
+++ b/app/(sharing)/[token]/[id]/page.tsx
@@ -1,4 +1,4 @@
-import { SharingPlaylogId, getSongsWithTitles } from "@/lib/api";
+import { generatePlaylogId, getSongsWithTitles } from "@/lib/api";
import { shareScore } from "../token";
export default async function Share({
@@ -12,7 +12,7 @@ export default async function Share({
const tokenResult = await shareScore(token);
if (tokenResult.error) {
- // Handle error appropriately, e.g., render an error message
+
return
{tokenResult.error}
;
}
@@ -20,13 +20,13 @@ export default async function Share({
const playlogId = parseInt(id);
const songsData = await getSongsWithTitles(userId);
- const playlogIds = await SharingPlaylogId(playlogId);
+ const playlogIds = await generatePlaylogId(playlogId);
- const matchingSongs = songsData.filter((song) =>
+ const matchSongToPlaylogId = songsData.filter((song) =>
playlogIds.includes(song.id)
);
- const songTitles = matchingSongs.map((song) => song.title);
+ const songTitles = matchSongToPlaylogId.map((song) => song.title);
return (
diff --git a/lib/api.ts b/lib/api.ts
index 485870d..ecbade7 100644
--- a/lib/api.ts
+++ b/lib/api.ts
@@ -1,14 +1,18 @@
"use server";
import { getAuth } from "@/auth/queries/getauth";
-import { artemis } from "@/lib/prisma";
-import { daphnis } from "@/lib/prisma";
+import { artemis, daphnis } from "@/lib/prisma";
import type * as Prisma from '@prisma/client';
+type ChuniScorePlaylog = Prisma.PrismaClient;
+type ChuniStaticMusic = Prisma.PrismaClient;
+type LinkSharingToken = {
+ playlogId: number;
+};
+
export async function getSongsWithTitles(userId: number) {
try {
- // Fetch songs from ChuniScorePlaylog
- const songs = await artemis.chuni_score_playlog.findMany({
+ const songs: ChuniScorePlaylog[] = await artemis.chuni_score_playlog.findMany({
where: {
user: userId,
},
@@ -55,15 +59,13 @@ export async function getSongsWithTitles(userId: number) {
placeId: true,
ticketId: true,
},
-
});
-
const musicIds = songs
.map((song) => song.musicId)
.filter((id) => id !== null) as number[];
- const staticMusicInfo = await artemis.chuni_static_music.findMany({
+ const staticMusicInfo: ChuniStaticMusic[] = await artemis.chuni_static_music.findMany({
where: {
songId: {
in: musicIds,
@@ -76,7 +78,6 @@ export async function getSongsWithTitles(userId: number) {
},
});
- // Map titles to songs based on musicId
const songsWithTitles = songs.map((song) => ({
...song,
title:
@@ -103,12 +104,11 @@ export async function SharingPlaylogId(playlogid: number) {
select: {
playlogId: true,
},
- });
+ }) as LinkSharingToken[];
- // Extracting playlogId values from the fetched tokens
- const playlogIds = tokens.map((token) => token.playlogId);
+ const playlogIds: number[] = tokens.map((token) => token.playlogId);
- return playlogIds; // Returning an array of playlogIds
+ return playlogIds;
} catch (error) {
console.error("Error fetching playlogIds:", error);
throw error;
@@ -116,7 +116,7 @@ export async function SharingPlaylogId(playlogid: number) {
}
export const getUsername = async () => {
- const { user } = await getAuth(); // Assuming getAuth() returns an auth object with user info
+ const { user } = await getAuth();
if (user) {
return await daphnis.user.findFirst({
where: {
@@ -125,7 +125,7 @@ export const getUsername = async () => {
},
});
}
- return null; // Return null if no user is found
+ return null;
};
export async function getAllAimeCards() {
diff --git a/lib/prisma.ts b/lib/prisma.ts
index 7b50e97..b257920 100644
--- a/lib/prisma.ts
+++ b/lib/prisma.ts
@@ -1,8 +1,8 @@
-import { PrismaClient as dahnisClient } from "@/prisma/schemas/daphnis/generated/daphnis";
+import { PrismaClient as daphnisClient } from "@/prisma/schemas/daphnis/generated/daphnis";
import { PrismaClient as artemisClient } from "@/prisma/schemas/artemis/generated/artemis";
const DaphnisSingleton = () => {
- return new dahnisClient();
+ return new daphnisClient();
};
const aremisSingleton = () => {