mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 17:54:44 +10:00
Tag connect & disconnect fix (#360)
* fix: tag connect/disconnect * fix: lint * fix: oidc typo fix
This commit is contained in:
@@ -160,6 +160,12 @@
|
|||||||
"add": "Add",
|
"add": "Add",
|
||||||
"cannotUndo": "This action cannot be undone.",
|
"cannotUndo": "This action cannot be undone.",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
|
"components": {
|
||||||
|
"multiitem": {
|
||||||
|
"new": "Create new: \"{0}\"",
|
||||||
|
"placeholder": "Start typing..."
|
||||||
|
}
|
||||||
|
},
|
||||||
"create": "Create",
|
"create": "Create",
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
@@ -181,13 +187,7 @@
|
|||||||
"servers": "Servers",
|
"servers": "Servers",
|
||||||
"srLoading": "Loading…",
|
"srLoading": "Loading…",
|
||||||
"tags": "Tags",
|
"tags": "Tags",
|
||||||
"today": "Today",
|
"today": "Today"
|
||||||
"components": {
|
|
||||||
"multiitem": {
|
|
||||||
"placeholder": "Start typing...",
|
|
||||||
"new": "Create new: \"{0}\""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"drop": {
|
"drop": {
|
||||||
"desc": "An open-source game distribution platform built for speed, flexibility and beauty.",
|
"desc": "An open-source game distribution platform built for speed, flexibility and beauty.",
|
||||||
|
|||||||
@@ -16,10 +16,19 @@ export default defineEventHandler(async (h3) => {
|
|||||||
|
|
||||||
const game = await prisma.game.findUnique({
|
const game = await prisma.game.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
select: { id: true },
|
select: { id: true, tags: { select: { id: true } } },
|
||||||
});
|
});
|
||||||
if (!game) throw createError({ statusCode: 404, message: "Game not found" });
|
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
|
// SAFETY: Okay to disable due to check above
|
||||||
// eslint-disable-next-line drop/no-prisma-delete
|
// eslint-disable-next-line drop/no-prisma-delete
|
||||||
await prisma.game.update({
|
await prisma.game.update({
|
||||||
@@ -28,7 +37,8 @@ export default defineEventHandler(async (h3) => {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
tags: {
|
tags: {
|
||||||
connect: body.tags.map((e) => ({ id: e })),
|
connect: toConnect.map((e) => ({ id: e })),
|
||||||
|
disconnect: toDisconnect.map((e) => ({ id: e })),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user