From b303fbcc9a52a937f725f192d6f995df632c0226 Mon Sep 17 00:00:00 2001 From: Polaris Date: Mon, 19 Aug 2024 19:12:39 -0400 Subject: [PATCH] added a check to make sure the user actually has the item unlocked --- .../avatarcustomization/actions.ts | 55 ++++++++++++++----- .../mapiconcustomization/actions.ts | 23 +++++++- .../nameplatecustomization/actions.ts | 28 +++++++++- .../systemvoicecustomization/actions.ts | 42 +++++++++++++- .../trophycustomization/actions.ts | 46 +++++++++++----- 5 files changed, 165 insertions(+), 29 deletions(-) diff --git a/components/(customization)/avatarcustomization/actions.ts b/components/(customization)/avatarcustomization/actions.ts index 182325e..62c2a64 100644 --- a/components/(customization)/avatarcustomization/actions.ts +++ b/components/(customization)/avatarcustomization/actions.ts @@ -43,31 +43,30 @@ export async function updateAvatarParts( try { // only including the values that aren't undefined i.e 0 - const AvatarPartData: any = {}; - if (avatarHead !== undefined) AvatarPartData.avatarHead = avatarHead; - if (avatarFace !== undefined) AvatarPartData.avatarFace = avatarFace; - if (avatarBack !== undefined) AvatarPartData.avatarBack = avatarBack; - if (avatarWear !== undefined) AvatarPartData.avatarWear = avatarWear; - if (avatarItem !== undefined) AvatarPartData.avatarItem = avatarItem; + const avatarPartData: any = {}; + if (avatarHead !== undefined) avatarPartData.avatarHead = avatarHead; + if (avatarFace !== undefined) avatarPartData.avatarFace = avatarFace; + if (avatarBack !== undefined) avatarPartData.avatarBack = avatarBack; + if (avatarWear !== undefined) avatarPartData.avatarWear = avatarWear; + if (avatarItem !== undefined) avatarPartData.avatarItem = avatarItem; - const UpdateAvatarHead = await artemis.chuni_profile_data.update({ + const updateAvatarParts = await artemis.chuni_profile_data.update({ where: { user_version: { user: user.UserId, version: supportedVersionNumber, }, }, - data: AvatarPartData, + data: avatarPartData, }); - console.log(UpdateAvatarHead); - - return UpdateAvatarHead; + return updateAvatarParts; } catch (error) { console.error("Error updating avatar parts:", error); throw error; } } + export async function getAllAvatarParts(category: number) { const { user } = await getAuth(); @@ -75,7 +74,21 @@ export async function getAllAvatarParts(category: number) { throw new Error("User is not authenticated or accessCode is missing"); } - const AllAvatarParts = await artemis.chuni_static_avatar.findMany({ + // Check for user items in _item_item + const checkUserItems = await artemis.chuni_item_item.findMany({ + where: { + itemKind: 11, + user: user.UserId, + }, + select: { + itemId: true, + }, + }); + + const chuni_item_item_ItemId = checkUserItems.map((item) => item.itemId); + + // Retrieve all avatar parts + const allAvatarParts = await artemis.chuni_static_avatar.findMany({ where: { category: category, }, @@ -89,5 +102,21 @@ export async function getAllAvatarParts(category: number) { texturePath: true, }, }); - return AllAvatarParts; + + const currentlyUnlockedAvatarParts = Array.from( + new Map( + allAvatarParts + .filter((matchingAvatarParts) => + chuni_item_item_ItemId.includes( + matchingAvatarParts.avatarAccessoryId, + ), + ) + .map((unlockedAvatarPart) => [ + unlockedAvatarPart.avatarAccessoryId, + unlockedAvatarPart, + ]), + ).values(), + ); + + return currentlyUnlockedAvatarParts; } diff --git a/components/(customization)/mapiconcustomization/actions.ts b/components/(customization)/mapiconcustomization/actions.ts index b9ee342..772db02 100644 --- a/components/(customization)/mapiconcustomization/actions.ts +++ b/components/(customization)/mapiconcustomization/actions.ts @@ -61,6 +61,18 @@ export async function getMapIcons() { throw new Error("User is not authenticated or accessCode is missing"); } + const checkIfMapIconIsUnlocked = await artemis.chuni_item_item.findMany({ + where: { + itemKind: 8, + user: user.UserId, + }, + select: { + itemId: true, + }, + }); + + const unlockedMapIcons = checkIfMapIconIsUnlocked.map((item) => item.itemId); + const AllMapIcons = await artemis.cozynet_chuni_static_mapicon.findMany({ select: { id: true, @@ -72,5 +84,14 @@ export async function getMapIcons() { netOpenName: true, }, }); - return AllMapIcons; + + const currentlyUnlockedMapIcons = Array.from( + new Map( + AllMapIcons.filter((matchingMapIconIds) => + unlockedMapIcons.includes(matchingMapIconIds.id), + ).map((unlockedMapIcons) => [unlockedMapIcons.id, unlockedMapIcons]), + ).values(), + ); + + return currentlyUnlockedMapIcons; } diff --git a/components/(customization)/nameplatecustomization/actions.ts b/components/(customization)/nameplatecustomization/actions.ts index 96dc5a0..5f3e900 100644 --- a/components/(customization)/nameplatecustomization/actions.ts +++ b/components/(customization)/nameplatecustomization/actions.ts @@ -63,6 +63,20 @@ export async function getNamePlates() { throw new Error("User is not authenticated or accessCode is missing"); } + const checkIfNamePlatetIsUnlocked = await artemis.chuni_item_item.findMany({ + where: { + itemKind: 1, + user: user.UserId, + }, + select: { + itemId: true, + }, + }); + + const unlockedNamePlates = checkIfNamePlatetIsUnlocked.map( + (item) => item.itemId, + ); + const AllNameplates = await artemis.cozynet_chuni_static_nameplate.findMany({ select: { id: true, @@ -74,5 +88,17 @@ export async function getNamePlates() { netOpenName: true, }, }); - return AllNameplates; + + const currentlyUnlockedNamePlates = Array.from( + new Map( + AllNameplates.filter((matchingNamePlateIds) => + unlockedNamePlates.includes(matchingNamePlateIds.id), + ).map((unlockedNamePlates) => [ + unlockedNamePlates.id, + unlockedNamePlates, + ]), + ).values(), + ); + + return currentlyUnlockedNamePlates; } diff --git a/components/(customization)/systemvoicecustomization/actions.ts b/components/(customization)/systemvoicecustomization/actions.ts index 23d6284..d524e94 100644 --- a/components/(customization)/systemvoicecustomization/actions.ts +++ b/components/(customization)/systemvoicecustomization/actions.ts @@ -34,6 +34,20 @@ export async function updatePlayerSystemVoiceId(voiceId: number) { throw new Error("nameplateId is required"); } + const checkIfSystemVoiceIsUnlocked = await artemis.chuni_item_item.findMany({ + where: { + itemKind: 10, + user: user.UserId, + }, + select: { + itemId: true, + }, + }); + + const unlockedSystemVoices = checkIfSystemVoiceIsUnlocked.map( + (item) => item.itemId, + ); + try { const updatePlayerNameplate = await artemis.chuni_profile_data.update({ where: { @@ -63,6 +77,20 @@ export async function getSystemVoices() { throw new Error("User is not authenticated or accessCode is missing"); } + const checkIfSystemVoiceIsUnlocked = await artemis.chuni_item_item.findMany({ + where: { + itemKind: 9, + user: user.UserId, + }, + select: { + itemId: true, + }, + }); + + const unlockedSystemVoices = checkIfSystemVoiceIsUnlocked.map( + (item) => item.itemId, + ); + const AllSystemVoices = await artemis.cozynet_chuni_static_systemvoice.findMany({ select: { @@ -75,5 +103,17 @@ export async function getSystemVoices() { netOpenName: true, }, }); - return AllSystemVoices; + + const currentlyUnlockedSystemVoices = Array.from( + new Map( + AllSystemVoices.filter((matchingsystemVoiceIds) => + unlockedSystemVoices.includes(matchingsystemVoiceIds.id), + ).map((unlockedSystemVoice) => [ + unlockedSystemVoice.id, + unlockedSystemVoice, + ]), + ).values(), + ); + + return currentlyUnlockedSystemVoices; } diff --git a/components/(customization)/trophycustomization/actions.ts b/components/(customization)/trophycustomization/actions.ts index c87238b..25e7195 100644 --- a/components/(customization)/trophycustomization/actions.ts +++ b/components/(customization)/trophycustomization/actions.ts @@ -63,17 +63,37 @@ export async function getTrophies() { throw new Error("User is not authenticated or accessCode is missing"); } - const AllStaticTrophies = - await artemis.cozynet_chuni_static_trophies.findMany({ - select: { - category: true, - netOpenName: true, - id: true, - str: true, - imagePath: true, - rareType: true, - sortName: true, - }, - }); - return AllStaticTrophies; + const checkIfTrophyIsUnlocked = await artemis.chuni_item_item.findMany({ + where: { + itemKind: 3, + user: user.UserId, + }, + select: { + itemId: true, + }, + }); + + const unlockedTrophies = checkIfTrophyIsUnlocked.map((item) => item.itemId); + + const AllTrophies = await artemis.cozynet_chuni_static_trophies.findMany({ + select: { + category: true, + netOpenName: true, + id: true, + str: true, + imagePath: true, + rareType: true, + sortName: true, + }, + }); + + const currentlyUnlockedTrophy = Array.from( + new Map( + AllTrophies.filter((matchingTrophyId) => + unlockedTrophies.includes(matchingTrophyId.id), + ).map((unlockedTrophy) => [unlockedTrophy.id, unlockedTrophy]), + ).values(), + ); + + return currentlyUnlockedTrophy; }