Skip to content

Commit 8dce023

Browse files
authored
add button to delete claimed items (#90)
* add button to delete claimed items * lint
1 parent caf170c commit 8dce023

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

src/lib/api/items.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export class ItemsAPI {
6262
return await fetch(`/api/items${path}`, options);
6363
};
6464

65-
delete = async (groupId?: string) => {
66-
return await this._makeRequest("DELETE", groupId ? `?groupId=${groupId}` : "");
65+
delete = async (groupId?: string, claimed?: boolean) => {
66+
const searchParams = new URLSearchParams();
67+
if (groupId) searchParams.append("groupId", groupId);
68+
if (claimed) searchParams.append("claimed", `${claimed}`);
69+
return await this._makeRequest("DELETE", "?" + searchParams.toString());
6770
};
6871
}

src/lib/components/admin/Actions/ClearListsButton.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { getModalStore, getToastStore, type ModalSettings } from "@skeletonlabs/skeleton";
55
66
export let groupId: string | undefined = undefined;
7+
export let claimed: boolean = false;
78
89
const modalStore = getModalStore();
910
const toastStore = getToastStore();
@@ -13,13 +14,13 @@
1314
const settings: ModalSettings = {
1415
type: "confirm",
1516
title: "Please Confirm",
16-
body: `Are you sure you wish to clear all wishlists ${
17-
groupId ? "" : "across <b>all groups</b>"
17+
body: `Are you sure you wish to clear ${claimed ? "claimed items" : "all wishlists"} ${
18+
groupId ? "in this group" : "across <b>all groups</b>"
1819
}? <b>This action is irreversible!</b>`,
1920
// confirm = TRUE | cancel = FALSE
2021
response: async (r: boolean) => {
2122
if (r) {
22-
const resp = await itemsAPI.delete(groupId);
23+
const resp = await itemsAPI.delete(groupId, claimed);
2324
2425
if (resp.ok) {
2526
invalidateAll();
@@ -45,5 +46,6 @@
4546
</script>
4647

4748
<button class="variant-filled-error btn w-fit" type="button" on:click={handleDelete}>
48-
Clear {groupId ? "" : "All"} Lists
49+
Clear {groupId ? "" : "All"}
50+
{claimed ? "Claimed Items" : "Lists"}
4951
</button>

src/lib/components/admin/ActionsForm.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
<div class="flex space-x-2">
66
<ClearListsButton />
7+
<ClearListsButton claimed />
78
</div>

src/routes/admin/groups/[groupId]/members/+page.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,6 @@
122122
<div>
123123
<button class="variant-filled-error btn w-fit" on:click={deleteGroup}>Delete Group</button>
124124
<ClearListsButton groupId={$page.params.groupId} />
125+
<ClearListsButton claimed groupId={$page.params.groupId} />
125126
</div>
126127
</div>

src/routes/api/items/+server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { _authCheck } from "../groups/[groupId]/auth";
66

77
export const DELETE: RequestHandler = async ({ locals, request }) => {
88
const groupId = new URL(request.url).searchParams.get("groupId");
9+
const claimed = new URL(request.url).searchParams.get("claimed");
910
if (groupId) {
1011
const { authenticated } = await _authCheck(locals.validate, groupId);
1112
if (!authenticated) {
@@ -24,7 +25,8 @@ export const DELETE: RequestHandler = async ({ locals, request }) => {
2425
try {
2526
const items = await client.item.deleteMany({
2627
where: {
27-
groupId: groupId ? groupId : undefined
28+
groupId: groupId ? groupId : undefined,
29+
pledgedById: claimed && Boolean(claimed) ? { not: null } : undefined
2830
}
2931
});
3032
return new Response(JSON.stringify(items), { status: 200 });

0 commit comments

Comments
 (0)