feat(delete games): update prisma & delete games

This commit is contained in:
DecDuck
2024-12-23 21:12:32 +11:00
parent fd4a7d1981
commit 089c3e03f6
8 changed files with 111 additions and 55 deletions

View File

@ -14,7 +14,7 @@
"@headlessui/vue": "^1.7.23", "@headlessui/vue": "^1.7.23",
"@heroicons/vue": "^2.1.5", "@heroicons/vue": "^2.1.5",
"@nuxt/content": "^2.13.4", "@nuxt/content": "^2.13.4",
"@prisma/client": "5.20.0", "@prisma/client": "^6.1.0",
"axios": "^1.7.7", "axios": "^1.7.7",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"cookie-es": "^1.2.2", "cookie-es": "^1.2.2",
@ -24,7 +24,7 @@
"markdown-it": "^14.1.0", "markdown-it": "^14.1.0",
"moment": "^2.30.1", "moment": "^2.30.1",
"nuxt": "^3.13.2", "nuxt": "^3.13.2",
"prisma": "^5.22.0", "prisma": "^6.1.0",
"sanitize-filename": "^1.6.3", "sanitize-filename": "^1.6.3",
"stream": "^0.0.3", "stream": "^0.0.3",
"stream-mime-type": "^2.0.0", "stream-mime-type": "^2.0.0",

View File

@ -85,12 +85,20 @@
</dd> </dd>
<dt class="sr-only">Metadata provider</dt> <dt class="sr-only">Metadata provider</dt>
</dl> </dl>
<NuxtLink <div class="inline-flex gap-x-2 items-center">
<NuxtLink
:href="`/admin/library/${game.id}`" :href="`/admin/library/${game.id}`"
class="mt-2 w-fit rounded-md bg-blue-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600" class="mt-2 w-fit rounded-md bg-blue-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
> >
Edit &rarr; Edit &rarr;
</NuxtLink> </NuxtLink>
<button
@click="() => deleteGame(game.id)"
class="mt-2 w-fit rounded-md bg-red-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
>
Delete
</button>
</div>
</div> </div>
</div> </div>
<div v-if="game.hasNotifications" class="flex flex-col gap-y-2 p-2"> <div v-if="game.hasNotifications" class="flex flex-col gap-y-2 p-2">
@ -173,22 +181,25 @@ const searchQuery = ref("");
const headers = useRequestHeaders(["cookie"]); const headers = useRequestHeaders(["cookie"]);
const libraryState = await $fetch("/api/v1/admin/library", { headers }); const libraryState = await $fetch("/api/v1/admin/library", { headers });
const libraryGames = libraryState.games.map((e) => { const libraryGames = ref(
const noVersions = e.status.noVersions; libraryState.games.map((e) => {
const toImport = e.status.unimportedVersions.length > 0; const noVersions = e.status.noVersions;
const toImport = e.status.unimportedVersions.length > 0;
return { return {
...e.game, ...e.game,
notifications: { notifications: {
noVersions, noVersions,
toImport, toImport,
}, },
hasNotifications: noVersions || toImport, hasNotifications: noVersions || toImport,
}; };
}); })
);
const filteredLibraryGames = computed(() => const filteredLibraryGames = computed(() =>
libraryGames.filter((e) => { // @ts-ignore
libraryGames.value.filter((e) => {
if (!searchQuery.value) return true; if (!searchQuery.value) return true;
const searchQueryLower = searchQuery.value.toLowerCase(); const searchQueryLower = searchQuery.value.toLowerCase();
if (e.mName.toLowerCase().includes(searchQueryLower)) return true; if (e.mName.toLowerCase().includes(searchQueryLower)) return true;
@ -197,4 +208,10 @@ const filteredLibraryGames = computed(() =>
return false; return false;
}) })
); );
async function deleteGame(id: string) {
await $fetch(`/api/v1/admin/game?id=${id}`, { method: "DELETE" });
const index = libraryGames.value.findIndex((e) => e.id === id);
libraryGames.value.splice(index, 1);
}
</script> </script>

View File

@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE "GameVersion" DROP CONSTRAINT "GameVersion_gameId_fkey";
-- AddForeignKey
ALTER TABLE "GameVersion" ADD CONSTRAINT "GameVersion_gameId_fkey" FOREIGN KEY ("gameId") REFERENCES "Game"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "_DeveloperToGame" ADD CONSTRAINT "_DeveloperToGame_AB_pkey" PRIMARY KEY ("A", "B");
-- DropIndex
DROP INDEX "_DeveloperToGame_AB_unique";
-- AlterTable
ALTER TABLE "_GameToPublisher" ADD CONSTRAINT "_GameToPublisher_AB_pkey" PRIMARY KEY ("A", "B");
-- DropIndex
DROP INDEX "_GameToPublisher_AB_unique";

View File

@ -1,3 +1,3 @@
# Please do not edit this file manually # Please do not edit this file manually
# It should be added in your version-control system (i.e. Git) # It should be added in your version-control system (e.g., Git)
provider = "postgresql" provider = "postgresql"

View File

@ -36,7 +36,7 @@ model Game {
// A particular set of files that relate to the version // A particular set of files that relate to the version
model GameVersion { model GameVersion {
gameId String gameId String
game Game @relation(fields: [gameId], references: [id]) game Game @relation(fields: [gameId], references: [id], onDelete: Cascade)
versionName String // Sub directory for the game files versionName String // Sub directory for the game files
created DateTime @default(now()) created DateTime @default(now())

View File

@ -0,0 +1,23 @@
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
export default defineEventHandler(async (h3) => {
const user = await h3.context.session.getAdminUser(h3);
if (!user) throw createError({ statusCode: 403 });
const query = getQuery(h3);
const gameId = query.id?.toString();
if (!gameId)
throw createError({
statusCode: 400,
statusMessage: "Missing id in query",
});
await prisma.game.delete({
where: {
id: gameId,
},
});
return {};
});

View File

@ -1037,46 +1037,46 @@
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.28.tgz#d45e01c4a56f143ee69c54dd6b12eade9e270a73" resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.28.tgz#d45e01c4a56f143ee69c54dd6b12eade9e270a73"
integrity sha512-8LduaNlMZGwdZ6qWrKlfa+2M4gahzFkprZiAt2TF8uS0qQgBizKXpXURqvTJ4WtmupWxaLqjRb2UCTe72mu+Aw== integrity sha512-8LduaNlMZGwdZ6qWrKlfa+2M4gahzFkprZiAt2TF8uS0qQgBizKXpXURqvTJ4WtmupWxaLqjRb2UCTe72mu+Aw==
"@prisma/client@5.20.0": "@prisma/client@^6.1.0":
version "5.20.0" version "6.1.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.20.0.tgz#4fc9f2b2341c9c997c139df4445688dd6b39663b" resolved "https://registry.yarnpkg.com/@prisma/client/-/client-6.1.0.tgz#179d3b70586e7be522f6f1f0a82cca01396f719a"
integrity sha512-CLv55ZuMuUawMsxoqxGtLT3bEZoa2W8L3Qnp6rDIFWy+ZBrUcOFKdoeGPSnbBqxc3SkdxJrF+D1veN/WNynZYA== integrity sha512-AbQYc5+EJKm1Ydfq3KxwcGiy7wIbm4/QbjCKWWoNROtvy7d6a3gmAGkKjK0iUCzh+rHV8xDhD5Cge8ke/kiy5Q==
"@prisma/debug@5.22.0": "@prisma/debug@6.1.0":
version "5.22.0" version "6.1.0"
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.22.0.tgz#58af56ed7f6f313df9fb1042b6224d3174bbf412" resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-6.1.0.tgz#a27a1d144f72a3bc95061ecb0255e7554d9d59ec"
integrity sha512-AUt44v3YJeggO2ZU5BkXI7M4hu9BF2zzH2iF2V5pyXT/lRTyWiElZ7It+bRH1EshoMRxHgpYg4VB6rCM+mG5jQ== integrity sha512-0himsvcM4DGBTtvXkd2Tggv6sl2JyUYLzEGXXleFY+7Kp6rZeSS3hiTW9mwtUlXrwYbJP6pwlVNB7jYElrjWUg==
"@prisma/engines-version@5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2": "@prisma/engines-version@6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959":
version "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2" version "6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2.tgz#d534dd7235c1ba5a23bacd5b92cc0ca3894c28f4" resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959.tgz#0b21ebf57362ffe35d0760c39855f90bbfa0f2fd"
integrity sha512-2PTmxFR2yHW/eB3uqWtcgRcgAbG1rwG9ZriSvQw+nnb7c4uCr3RAcGMb6/zfE88SKlC1Nj2ziUvc96Z379mHgQ== integrity sha512-PdJqmYM2Fd8K0weOOtQThWylwjsDlTig+8Pcg47/jszMuLL9iLIaygC3cjWJLda69siRW4STlCTMSgOjZzvKPQ==
"@prisma/engines@5.22.0": "@prisma/engines@6.1.0":
version "5.22.0" version "6.1.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.22.0.tgz#28f3f52a2812c990a8b66eb93a0987816a5b6d84" resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-6.1.0.tgz#2195244a8ce33839a8131e4465624e21d1f8d042"
integrity sha512-UNjfslWhAt06kVL3CjkuYpHAWSO6L4kDCVPegV6itt7nD1kSJavd3vhgAEhjglLJJKEdJ7oIqDJ+yHk6qO8gPA== integrity sha512-GnYJbCiep3Vyr1P/415ReYrgJUjP79fBNc1wCo7NP6Eia0CzL2Ot9vK7Infczv3oK7JLrCcawOSAxFxNFsAERQ==
dependencies: dependencies:
"@prisma/debug" "5.22.0" "@prisma/debug" "6.1.0"
"@prisma/engines-version" "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2" "@prisma/engines-version" "6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959"
"@prisma/fetch-engine" "5.22.0" "@prisma/fetch-engine" "6.1.0"
"@prisma/get-platform" "5.22.0" "@prisma/get-platform" "6.1.0"
"@prisma/fetch-engine@5.22.0": "@prisma/fetch-engine@6.1.0":
version "5.22.0" version "6.1.0"
resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.22.0.tgz#4fb691b483a450c5548aac2f837b267dd50ef52e" resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-6.1.0.tgz#2a5174787bf57c9b1d5d400bb923e0dc6a73a794"
integrity sha512-bkrD/Mc2fSvkQBV5EpoFcZ87AvOgDxbG99488a5cexp5Ccny+UM6MAe/UFkUC0wLYD9+9befNOqGiIJhhq+HbA== integrity sha512-asdFi7TvPlEZ8CzSZ/+Du5wZ27q6OJbRSXh+S8ISZguu+S9KtS/gP7NeXceZyb1Jv1SM1S5YfiCv+STDsG6rrg==
dependencies: dependencies:
"@prisma/debug" "5.22.0" "@prisma/debug" "6.1.0"
"@prisma/engines-version" "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2" "@prisma/engines-version" "6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959"
"@prisma/get-platform" "5.22.0" "@prisma/get-platform" "6.1.0"
"@prisma/get-platform@5.22.0": "@prisma/get-platform@6.1.0":
version "5.22.0" version "6.1.0"
resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.22.0.tgz#fc675bc9d12614ca2dade0506c9c4a77e7dddacd" resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-6.1.0.tgz#d4394a24ef91af6675a92382ed40e6e6e07eeb13"
integrity sha512-pHhpQdr1UPFpt+zFfnPazhulaZYCUqeIcPpJViYoq9R+D/yw4fjE+CtnsnKzPYm0ddUbeXUzjGVGIRVgPDCk4Q== integrity sha512-ia8bNjboBoHkmKGGaWtqtlgQOhCi7+f85aOkPJKgNwWvYrT6l78KgojLekE8zMhVk0R9lWcifV0Pf8l3/15V0Q==
dependencies: dependencies:
"@prisma/debug" "5.22.0" "@prisma/debug" "6.1.0"
"@redocly/ajv@^8.11.2": "@redocly/ajv@^8.11.2":
version "8.11.2" version "8.11.2"
@ -5317,12 +5317,12 @@ pretty-bytes@^6.1.1:
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-6.1.1.tgz#38cd6bb46f47afbf667c202cfc754bffd2016a3b" resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-6.1.1.tgz#38cd6bb46f47afbf667c202cfc754bffd2016a3b"
integrity sha512-mQUvGU6aUFQ+rNvTIAcZuWGRT9a6f6Yrg9bHs4ImKF+HZCEK+plBvnAZYSIQztknZF2qnzNtr6F8s0+IuptdlQ== integrity sha512-mQUvGU6aUFQ+rNvTIAcZuWGRT9a6f6Yrg9bHs4ImKF+HZCEK+plBvnAZYSIQztknZF2qnzNtr6F8s0+IuptdlQ==
prisma@^5.22.0: prisma@^6.1.0:
version "5.22.0" version "6.1.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.22.0.tgz#1f6717ff487cdef5f5799cc1010459920e2e6197" resolved "https://registry.yarnpkg.com/prisma/-/prisma-6.1.0.tgz#738f657fdd5ab8e6775f385db81bf7e61c70fbaf"
integrity sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A== integrity sha512-aFI3Yi+ApUxkwCJJwyQSwpyzUX7YX3ihzuHNHOyv4GJg3X5tQsmRaJEnZ+ZyfHpMtnyahhmXVfbTZ+lS8ZtfKw==
dependencies: dependencies:
"@prisma/engines" "5.22.0" "@prisma/engines" "6.1.0"
optionalDependencies: optionalDependencies:
fsevents "2.3.3" fsevents "2.3.3"