added a check to make sure the user actually has the item unlocked
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,19 @@ 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: {
|
||||||
|
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: {
|
select: {
|
||||||
category: true,
|
category: true,
|
||||||
netOpenName: true,
|
netOpenName: true,
|
||||||
@ -75,5 +86,14 @@ export async function getTrophies() {
|
|||||||
sortName: true,
|
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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user