Fix issue with deleting of a wishlist

Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
Benny Samir Hierl 2022-02-20 15:48:35 +01:00
parent b026132c32
commit 71ab2c14fd
5 changed files with 30 additions and 7 deletions

4
package-lock.json generated
View file

@ -1,11 +1,11 @@
{
"name": "wishlist",
"version": "1.0.0",
"version": "1.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.0.0",
"version": "1.0.1",
"dependencies": {
"@prisma/client": "^3.9.2",
"@tailwindcss/line-clamp": "^0.3.1",

View file

@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.1",
"scripts": {
"dev": "concurrently --kill-others \"npm run dev:frontend\" \"npm run dev:backend\"",
"demo": "npm run build && prisma migrate deploy && prisma migrate reset -f && node dist/api/server.js",

View file

@ -0,0 +1,17 @@
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Item" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"title" TEXT NOT NULL,
"url" TEXT NOT NULL DEFAULT '',
"imageSrc" TEXT NOT NULL DEFAULT '',
"description" TEXT NOT NULL,
"bought" BOOLEAN NOT NULL DEFAULT false,
"wishlistId" TEXT NOT NULL,
CONSTRAINT "Item_wishlistId_fkey" FOREIGN KEY ("wishlistId") REFERENCES "Wishlist" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_Item" ("bought", "description", "id", "imageSrc", "title", "url", "wishlistId") SELECT "bought", "description", "id", "imageSrc", "title", "url", "wishlistId" FROM "Item";
DROP TABLE "Item";
ALTER TABLE "new_Item" RENAME TO "Item";
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;

View file

@ -27,6 +27,6 @@ model Item {
imageSrc String @default("")
description String
bought Boolean @default(false)
wishlist Wishlist @relation(fields: [wishlistId], references: [id])
wishlist Wishlist @relation(fields: [wishlistId], references: [id], onDelete: Cascade)
wishlistId String
}

View file

@ -41,7 +41,9 @@ const updateWishlist = async (updatedData: Wishlist): Promise<void> => {
}
const deleteWishlist = async (): Promise<void> => {
const { error } = await useFetch(`/wishlist/${state!.value!.id}`).delete()
const { error } = await useFetch(`/wishlist/${state!.value!.id}`)
.delete()
.json()
if (error.value) {
throw error.value
}
@ -92,7 +94,9 @@ const updateItem = async (
const itemBought = async (item: WishlistItem): Promise<void> => {
const { error } = await useFetch(
`/wishlist/${item.wishlistId}/item/${item.id}/bought`
).post()
)
.post()
.json()
if (error.value) {
throw error.value
}
@ -102,7 +106,9 @@ const itemBought = async (item: WishlistItem): Promise<void> => {
const itemDelete = async (item: WishlistItem): Promise<void> => {
const { error } = await useFetch(
`/wishlist/${item.wishlistId}/item/${item.id}`
).delete()
)
.delete()
.json()
if (error.value) {
throw error.value
}