arcana type magic

This commit is contained in:
polaris
2024-06-29 03:02:21 -04:00
parent 22b1c6c8d9
commit bde370314e
3 changed files with 21 additions and 21 deletions

View File

@ -1,4 +1,4 @@
import { SharingPlaylogId, getSongsWithTitles } from "@/lib/api"; import { generatePlaylogId, getSongsWithTitles } from "@/lib/api";
import { shareScore } from "../token"; import { shareScore } from "../token";
export default async function Share({ export default async function Share({
@ -12,7 +12,7 @@ export default async function Share({
const tokenResult = await shareScore(token); const tokenResult = await shareScore(token);
if (tokenResult.error) { if (tokenResult.error) {
// Handle error appropriately, e.g., render an error message
return <p>{tokenResult.error}</p>; return <p>{tokenResult.error}</p>;
} }
@ -20,13 +20,13 @@ export default async function Share({
const playlogId = parseInt(id); const playlogId = parseInt(id);
const songsData = await getSongsWithTitles(userId); 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) playlogIds.includes(song.id)
); );
const songTitles = matchingSongs.map((song) => song.title); const songTitles = matchSongToPlaylogId.map((song) => song.title);
return ( return (
<ul> <ul>

View File

@ -1,14 +1,18 @@
"use server"; "use server";
import { getAuth } from "@/auth/queries/getauth"; import { getAuth } from "@/auth/queries/getauth";
import { artemis } from "@/lib/prisma"; import { artemis, daphnis } from "@/lib/prisma";
import { daphnis } from "@/lib/prisma";
import type * as Prisma from '@prisma/client'; 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) { export async function getSongsWithTitles(userId: number) {
try { try {
// Fetch songs from ChuniScorePlaylog const songs: ChuniScorePlaylog[] = await artemis.chuni_score_playlog.findMany({
const songs = await artemis.chuni_score_playlog.findMany({
where: { where: {
user: userId, user: userId,
}, },
@ -55,15 +59,13 @@ export async function getSongsWithTitles(userId: number) {
placeId: true, placeId: true,
ticketId: true, ticketId: true,
}, },
}); });
const musicIds = songs const musicIds = songs
.map((song) => song.musicId) .map((song) => song.musicId)
.filter((id) => id !== null) as number[]; .filter((id) => id !== null) as number[];
const staticMusicInfo = await artemis.chuni_static_music.findMany({ const staticMusicInfo: ChuniStaticMusic[] = await artemis.chuni_static_music.findMany({
where: { where: {
songId: { songId: {
in: musicIds, in: musicIds,
@ -76,7 +78,6 @@ export async function getSongsWithTitles(userId: number) {
}, },
}); });
// Map titles to songs based on musicId
const songsWithTitles = songs.map((song) => ({ const songsWithTitles = songs.map((song) => ({
...song, ...song,
title: title:
@ -103,12 +104,11 @@ export async function SharingPlaylogId(playlogid: number) {
select: { select: {
playlogId: true, playlogId: true,
}, },
}); }) as LinkSharingToken[];
// Extracting playlogId values from the fetched tokens const playlogIds: number[] = tokens.map((token) => token.playlogId);
const playlogIds = tokens.map((token) => token.playlogId);
return playlogIds; // Returning an array of playlogIds return playlogIds;
} catch (error) { } catch (error) {
console.error("Error fetching playlogIds:", error); console.error("Error fetching playlogIds:", error);
throw error; throw error;
@ -116,7 +116,7 @@ export async function SharingPlaylogId(playlogid: number) {
} }
export const getUsername = async () => { export const getUsername = async () => {
const { user } = await getAuth(); // Assuming getAuth() returns an auth object with user info const { user } = await getAuth();
if (user) { if (user) {
return await daphnis.user.findFirst({ return await daphnis.user.findFirst({
where: { where: {
@ -125,7 +125,7 @@ export const getUsername = async () => {
}, },
}); });
} }
return null; // Return null if no user is found return null;
}; };
export async function getAllAimeCards() { export async function getAllAimeCards() {

View File

@ -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"; import { PrismaClient as artemisClient } from "@/prisma/schemas/artemis/generated/artemis";
const DaphnisSingleton = () => { const DaphnisSingleton = () => {
return new dahnisClient(); return new daphnisClient();
}; };
const aremisSingleton = () => { const aremisSingleton = () => {