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