implement deletion of admin user, frontend and backend

This commit is contained in:
2025-08-06 11:52:39 +02:00
parent 7e87a01c59
commit cbea96f892
3 changed files with 46 additions and 2 deletions

View File

@@ -65,8 +65,21 @@
}, 5000);
}
async function deleteUser() {
async function deleteUser(userId: number) {
const URL = `/api/users/${userId}`;
const response = await fetch(URL, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
})
if (response.status == 204) {
userList = await getUsers();
} else {
alert("Nutzer konnte nicht gelöscht werden")
}
}
</script>

View File

@@ -0,0 +1,13 @@
import { json } from '@sveltejs/kit';
import { deleteUser } from '$lib/server/userService';
export async function DELETE({ params, locals }) {
if (!locals.user) {
return json({ error: 'Unauthorized' }, { status: 401 });
}
const userId = params.user;
const rowCount = deleteUser(userId);
return new Response(null, { status: rowCount == 1 ? 204 : 400 });
}