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 {
// 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -63,8 +63,19 @@ export async function getTrophies() {
throw new Error("User is not authenticated or accessCode is missing");
}
const AllStaticTrophies =
await artemis.cozynet_chuni_static_trophies.findMany({
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,
@ -75,5 +86,14 @@ export async function getTrophies() {
sortName: true,
},
});
return AllStaticTrophies;
const currentlyUnlockedTrophy = Array.from(
new Map(
AllTrophies.filter((matchingTrophyId) =>
unlockedTrophies.includes(matchingTrophyId.id),
).map((unlockedTrophy) => [unlockedTrophy.id, unlockedTrophy]),
).values(),
);
return currentlyUnlockedTrophy;
}