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

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