Files
warren/frontend/lib/api/admin/deleteUserWarren.ts
2025-07-21 19:27:41 +02:00

53 lines
1.3 KiB
TypeScript

import type { UserWarren } from '~/shared/types/warrens';
import { getApiHeaders } from '..';
import { toast } from 'vue-sonner';
import type { ApiResponse } from '~/shared/types/api';
export async function deleteUserWarren(
userId: string,
warrenId: string
): Promise<{ success: true; data: UserWarren } | { success: false }> {
const { data, error } = await useFetch<ApiResponse<UserWarren>>(
getApiUrl('admin/user-warrens'),
{
method: 'DELETE',
headers: getApiHeaders(),
body: JSON.stringify({
userId: userId,
warrenId: warrenId,
}),
responseType: 'json',
}
);
if (data.value == null) {
toast.error('Delete user warren', {
description: error.value?.data ?? 'Failed to delete user warren',
});
return {
success: false,
};
}
const keys = ['admin-resources'];
const session = useAuthSession();
if (
session.value != null &&
data.value.data.userId === session.value.user.id
) {
keys.push('warrens');
}
await refreshNuxtData(keys);
toast.success('Delete user warren', {
description: 'Successfully deleted user warren',
});
return {
success: true,
data: data.value.data,
};
}