Skip to content

Commit

Permalink
DELETE route
Browse files Browse the repository at this point in the history
  • Loading branch information
jho44 committed Oct 1, 2023
1 parent d7a9d2a commit 0a2a6e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/routes/db/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ export async function POST({
await acceptHouseholdInvite(req, user);
} else if (req.type === 'rejectHouseholdInvite') {
await deleteHouseholdInvite(req, user);
} else if (req.type === 'deleteUser') {
await deleteUser(user);
} else {
throw error(400, {
message: `The request type ${req.type} isn't supported`
message: `The request type ${req.type} isn't supported in /db POST req`
});
}

Expand All @@ -120,6 +118,12 @@ export async function DELETE({

if (req.type === 'householdChild') await deleteKid(req, user);
else if (req.type === 'household') await deleteHousehold(user);
else if (req.type === 'user') await deleteUser(user);
else {
throw error(400, {
message: `The request type ${req.type} isn't supported in /db DELETE req`
});
}
return json('success');
}

Expand Down
12 changes: 8 additions & 4 deletions src/routes/household/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,13 @@
}
async function deleteAcc() {
const response = await writeReq('/db', {
type: 'deleteUser'
});
const response = await writeReq(
'/db',
{
type: 'user'
},
'DELETE'
);
if (response.status == 200) {
document.cookie = 'session=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
await goto('/');
Expand Down Expand Up @@ -368,7 +372,7 @@
{/key}

<Modal bind:showModal>
<h2 slot="header">{modalText.heading}</h2>
<h2 slot="header" style="margin-top: 0">{modalText.heading}</h2>

<p>{modalText.content}</p>

Expand Down

0 comments on commit 0a2a6e9

Please sign in to comment.