import type { ApiResponse } from '~/shared/types/api'; import type { AdminWarrenData } from '~/shared/types/warrens'; import { getApiHeaders } from '..'; import { toast } from 'vue-sonner'; export async function createWarren( name: string, path: string ): Promise<{ success: true; warren: AdminWarrenData } | { success: false }> { const { data, error } = await useFetch>( getApiUrl('admin/warrens'), { method: 'POST', headers: getApiHeaders(), body: JSON.stringify({ name: name, path: path, }), responseType: 'json', } ); if (data.value == null) { toast.error('Create warren', { description: error.value?.data ?? 'Failed to create warren', }); return { success: false, }; } await refreshNuxtData('admin-resources'); toast.success('Create warren', { description: 'Successfully created warren', }); return { success: true, warren: data.value.data, }; }