Tag connect & disconnect fix (#360)

* fix: tag connect/disconnect

* fix: lint

* fix: oidc typo fix
This commit is contained in:
DecDuck
2026-02-27 04:15:27 +00:00
committed by GitHub
parent 7fa02c57d1
commit 2d2b815441
4 changed files with 19 additions and 9 deletions
+12 -2
View File
@@ -16,10 +16,19 @@ export default defineEventHandler(async (h3) => {
const game = await prisma.game.findUnique({
where: { id },
select: { id: true },
select: { id: true, tags: { select: { id: true } } },
});
if (!game) throw createError({ statusCode: 404, message: "Game not found" });
const tagSet = new Set(game.tags.map((v) => v.id));
const toConnect = body.tags.filter((v) => !tagSet.has(v));
const bodyTagSet = new Set(body.tags);
const toDisconnect = tagSet
.values()
.filter((v) => !bodyTagSet.has(v))
.toArray();
// SAFETY: Okay to disable due to check above
// eslint-disable-next-line drop/no-prisma-delete
await prisma.game.update({
@@ -28,7 +37,8 @@ export default defineEventHandler(async (h3) => {
},
data: {
tags: {
connect: body.tags.map((e) => ({ id: e })),
connect: toConnect.map((e) => ({ id: e })),
disconnect: toDisconnect.map((e) => ({ id: e })),
},
},
});