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

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