added a check to make sure the user actually has the item unlocked

This commit is contained in:
Polaris
2024-08-19 19:12:39 -04:00
parent 458bbfba48
commit b303fbcc9a
5 changed files with 165 additions and 29 deletions

View File

@ -43,31 +43,30 @@ export async function updateAvatarParts(
try { try {
// only including the values that aren't undefined i.e 0 // only including the values that aren't undefined i.e 0
const AvatarPartData: any = {}; const avatarPartData: any = {};
if (avatarHead !== undefined) AvatarPartData.avatarHead = avatarHead; if (avatarHead !== undefined) avatarPartData.avatarHead = avatarHead;
if (avatarFace !== undefined) AvatarPartData.avatarFace = avatarFace; if (avatarFace !== undefined) avatarPartData.avatarFace = avatarFace;
if (avatarBack !== undefined) AvatarPartData.avatarBack = avatarBack; if (avatarBack !== undefined) avatarPartData.avatarBack = avatarBack;
if (avatarWear !== undefined) AvatarPartData.avatarWear = avatarWear; if (avatarWear !== undefined) avatarPartData.avatarWear = avatarWear;
if (avatarItem !== undefined) AvatarPartData.avatarItem = avatarItem; if (avatarItem !== undefined) avatarPartData.avatarItem = avatarItem;
const UpdateAvatarHead = await artemis.chuni_profile_data.update({ const updateAvatarParts = await artemis.chuni_profile_data.update({
where: { where: {
user_version: { user_version: {
user: user.UserId, user: user.UserId,
version: supportedVersionNumber, version: supportedVersionNumber,
}, },
}, },
data: AvatarPartData, data: avatarPartData,
}); });
console.log(UpdateAvatarHead); return updateAvatarParts;
return UpdateAvatarHead;
} catch (error) { } catch (error) {
console.error("Error updating avatar parts:", error); console.error("Error updating avatar parts:", error);
throw error; throw error;
} }
} }
export async function getAllAvatarParts(category: number) { export async function getAllAvatarParts(category: number) {
const { user } = await getAuth(); 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"); 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: { where: {
category: category, category: category,
}, },
@ -89,5 +102,21 @@ export async function getAllAvatarParts(category: number) {
texturePath: true, 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;
} }

View File

@ -61,6 +61,18 @@ export async function getMapIcons() {
throw new Error("User is not authenticated or accessCode is missing"); 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({ const AllMapIcons = await artemis.cozynet_chuni_static_mapicon.findMany({
select: { select: {
id: true, id: true,
@ -72,5 +84,14 @@ export async function getMapIcons() {
netOpenName: true, 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;
} }

View File

@ -63,6 +63,20 @@ export async function getNamePlates() {
throw new Error("User is not authenticated or accessCode is missing"); 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({ const AllNameplates = await artemis.cozynet_chuni_static_nameplate.findMany({
select: { select: {
id: true, id: true,
@ -74,5 +88,17 @@ export async function getNamePlates() {
netOpenName: true, 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;
} }

View File

@ -34,6 +34,20 @@ export async function updatePlayerSystemVoiceId(voiceId: number) {
throw new Error("nameplateId is required"); 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 { try {
const updatePlayerNameplate = await artemis.chuni_profile_data.update({ const updatePlayerNameplate = await artemis.chuni_profile_data.update({
where: { where: {
@ -63,6 +77,20 @@ export async function getSystemVoices() {
throw new Error("User is not authenticated or accessCode is missing"); 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 = const AllSystemVoices =
await artemis.cozynet_chuni_static_systemvoice.findMany({ await artemis.cozynet_chuni_static_systemvoice.findMany({
select: { select: {
@ -75,5 +103,17 @@ export async function getSystemVoices() {
netOpenName: true, 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;
} }

View File

@ -63,17 +63,37 @@ export async function getTrophies() {
throw new Error("User is not authenticated or accessCode is missing"); throw new Error("User is not authenticated or accessCode is missing");
} }
const AllStaticTrophies = const checkIfTrophyIsUnlocked = await artemis.chuni_item_item.findMany({
await artemis.cozynet_chuni_static_trophies.findMany({ where: {
select: { itemKind: 3,
category: true, user: user.UserId,
netOpenName: true, },
id: true, select: {
str: true, itemId: true,
imagePath: true, },
rareType: true, });
sortName: true,
}, const unlockedTrophies = checkIfTrophyIsUnlocked.map((item) => item.itemId);
});
return AllStaticTrophies; 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;
} }