daphnis/components/(customization)/avatarcustomization/actions.ts
2024-07-26 13:19:37 -04:00

57 lines
1.3 KiB
TypeScript

"use server";
import { getAuth } from "@/auth/queries/getauth";
import { artemis, daphnis } from "@/lib/prisma";
import type * as Prisma from "@prisma/client";
// type ChuniScorePlaylog = Prisma.PrismaClient;
// type ChuniStaticMusic = Prisma.PrismaClient;
export async function getCurrentAvatarParts() {
const { user } = await getAuth();
if (!user || !user.accessCode) {
throw new Error("User is not authenticated or accessCode is missing");
}
const avatarParts = await artemis.chuni_profile_data.findMany({
where: {
user: user.UserId,
},
select: {
avatarSkin: true,
avatarBack: true,
avatarFace: true,
avatarFront: true,
avatarHead: true,
avatarItem: true,
avatarWear: true,
},
});
return avatarParts;
}
export async function getAllAvatarParts(category: number) {
const { user } = await getAuth();
if (!user || !user.accessCode) {
throw new Error("User is not authenticated or accessCode is missing");
}
const avatarParts = await artemis.chuni_static_avatar.findMany({
where: {
category: category,
},
select: {
id: true,
name: true,
avatarAccessoryId: true,
category: true,
version: true,
iconPath: true,
texturePath: true,
},
});
return avatarParts;
}