Skip to content

Commit 2d2b815

Browse files
authored
Tag connect & disconnect fix (#360)
* fix: tag connect/disconnect * fix: lint * fix: oidc typo fix
1 parent 7fa02c5 commit 2d2b815

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

i18n/locales/en_us.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@
160160
"add": "Add",
161161
"cannotUndo": "This action cannot be undone.",
162162
"close": "Close",
163+
"components": {
164+
"multiitem": {
165+
"new": "Create new: \"{0}\"",
166+
"placeholder": "Start typing..."
167+
}
168+
},
163169
"create": "Create",
164170
"date": "Date",
165171
"delete": "Delete",
@@ -181,13 +187,7 @@
181187
"servers": "Servers",
182188
"srLoading": "Loading…",
183189
"tags": "Tags",
184-
"today": "Today",
185-
"components": {
186-
"multiitem": {
187-
"placeholder": "Start typing...",
188-
"new": "Create new: \"{0}\""
189-
}
190-
}
190+
"today": "Today"
191191
},
192192
"drop": {
193193
"desc": "An open-source game distribution platform built for speed, flexibility and beauty.",

server/api/v1/admin/game/[id]/tags.patch.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ export default defineEventHandler(async (h3) => {
1616

1717
const game = await prisma.game.findUnique({
1818
where: { id },
19-
select: { id: true },
19+
select: { id: true, tags: { select: { id: true } } },
2020
});
2121
if (!game) throw createError({ statusCode: 404, message: "Game not found" });
2222

23+
const tagSet = new Set(game.tags.map((v) => v.id));
24+
const toConnect = body.tags.filter((v) => !tagSet.has(v));
25+
26+
const bodyTagSet = new Set(body.tags);
27+
const toDisconnect = tagSet
28+
.values()
29+
.filter((v) => !bodyTagSet.has(v))
30+
.toArray();
31+
2332
// SAFETY: Okay to disable due to check above
2433
// eslint-disable-next-line drop/no-prisma-delete
2534
await prisma.game.update({
@@ -28,7 +37,8 @@ export default defineEventHandler(async (h3) => {
2837
},
2938
data: {
3039
tags: {
31-
connect: body.tags.map((e) => ({ id: e })),
40+
connect: toConnect.map((e) => ({ id: e })),
41+
disconnect: toDisconnect.map((e) => ({ id: e })),
3242
},
3343
},
3444
});

0 commit comments

Comments
 (0)