From d8ac8e484052e9ccc41e006962b399b03dd82c48 Mon Sep 17 00:00:00 2001 From: Carter Mintey Date: Fri, 29 Dec 2023 23:09:08 -0600 Subject: [PATCH 1/2] add button to delete claimed items --- src/lib/api/items.ts | 7 +++++-- .../components/admin/Actions/ClearListsButton.svelte | 10 ++++++---- src/lib/components/admin/ActionsForm.svelte | 1 + src/routes/admin/groups/[groupId]/members/+page.svelte | 1 + src/routes/api/items/+server.ts | 4 +++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lib/api/items.ts b/src/lib/api/items.ts index eedfc67..052b417 100644 --- a/src/lib/api/items.ts +++ b/src/lib/api/items.ts @@ -62,7 +62,10 @@ export class ItemsAPI { return await fetch(`/api/items${path}`, options); }; - delete = async (groupId?: string) => { - return await this._makeRequest("DELETE", groupId ? `?groupId=${groupId}` : ""); + delete = async (groupId?: string, claimed?: boolean) => { + const searchParams = new URLSearchParams() + if (groupId) searchParams.append("groupId", groupId) + if (claimed) searchParams.append("claimed", `${claimed}`) + return await this._makeRequest("DELETE", "?" + searchParams.toString()); }; } diff --git a/src/lib/components/admin/Actions/ClearListsButton.svelte b/src/lib/components/admin/Actions/ClearListsButton.svelte index be9d9ba..12b2a59 100644 --- a/src/lib/components/admin/Actions/ClearListsButton.svelte +++ b/src/lib/components/admin/Actions/ClearListsButton.svelte @@ -4,6 +4,7 @@ import { getModalStore, getToastStore, type ModalSettings } from "@skeletonlabs/skeleton"; export let groupId: string | undefined = undefined; + export let claimed: boolean = false; const modalStore = getModalStore(); const toastStore = getToastStore(); @@ -13,13 +14,13 @@ const settings: ModalSettings = { type: "confirm", title: "Please Confirm", - body: `Are you sure you wish to clear all wishlists ${ - groupId ? "" : "across all groups" + body: `Are you sure you wish to clear ${claimed ? "claimed items" : "all wishlists"} ${ + groupId ? "in this group" : "across all groups" }? This action is irreversible!`, // confirm = TRUE | cancel = FALSE response: async (r: boolean) => { if (r) { - const resp = await itemsAPI.delete(groupId); + const resp = await itemsAPI.delete(groupId, claimed); if (resp.ok) { invalidateAll(); @@ -45,5 +46,6 @@ diff --git a/src/lib/components/admin/ActionsForm.svelte b/src/lib/components/admin/ActionsForm.svelte index 24bd458..1220d19 100644 --- a/src/lib/components/admin/ActionsForm.svelte +++ b/src/lib/components/admin/ActionsForm.svelte @@ -4,4 +4,5 @@
+
diff --git a/src/routes/admin/groups/[groupId]/members/+page.svelte b/src/routes/admin/groups/[groupId]/members/+page.svelte index aa14a54..484621a 100644 --- a/src/routes/admin/groups/[groupId]/members/+page.svelte +++ b/src/routes/admin/groups/[groupId]/members/+page.svelte @@ -122,5 +122,6 @@
+
diff --git a/src/routes/api/items/+server.ts b/src/routes/api/items/+server.ts index 9f5cb6f..f2c1d5a 100644 --- a/src/routes/api/items/+server.ts +++ b/src/routes/api/items/+server.ts @@ -6,6 +6,7 @@ import { _authCheck } from "../groups/[groupId]/auth"; export const DELETE: RequestHandler = async ({ locals, request }) => { const groupId = new URL(request.url).searchParams.get("groupId"); + const claimed = new URL(request.url).searchParams.get("claimed"); if (groupId) { const { authenticated } = await _authCheck(locals.validate, groupId); if (!authenticated) { @@ -24,7 +25,8 @@ export const DELETE: RequestHandler = async ({ locals, request }) => { try { const items = await client.item.deleteMany({ where: { - groupId: groupId ? groupId : undefined + groupId: groupId ? groupId : undefined, + pledgedById: claimed && Boolean(claimed) ? { not: null } : undefined } }); return new Response(JSON.stringify(items), { status: 200 }); From 9cd1eb04fdcb0a91803f2c74a36c63d7e0787689 Mon Sep 17 00:00:00 2001 From: Carter Mintey Date: Fri, 29 Dec 2023 23:11:08 -0600 Subject: [PATCH 2/2] lint --- src/lib/api/items.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/api/items.ts b/src/lib/api/items.ts index 052b417..dca8399 100644 --- a/src/lib/api/items.ts +++ b/src/lib/api/items.ts @@ -63,9 +63,9 @@ export class ItemsAPI { }; delete = async (groupId?: string, claimed?: boolean) => { - const searchParams = new URLSearchParams() - if (groupId) searchParams.append("groupId", groupId) - if (claimed) searchParams.append("claimed", `${claimed}`) + const searchParams = new URLSearchParams(); + if (groupId) searchParams.append("groupId", groupId); + if (claimed) searchParams.append("claimed", `${claimed}`); return await this._makeRequest("DELETE", "?" + searchParams.toString()); }; }