46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
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 editWarren(
|
|
warrenId: string,
|
|
name: string,
|
|
path: string
|
|
): Promise<{ success: true; warren: AdminWarrenData } | { success: false }> {
|
|
const { data, error } = await useFetch<ApiResponse<AdminWarrenData>>(
|
|
getApiUrl('admin/warrens'),
|
|
{
|
|
method: 'PATCH',
|
|
headers: getApiHeaders(),
|
|
body: JSON.stringify({
|
|
id: warrenId,
|
|
name: name,
|
|
path: path,
|
|
}),
|
|
responseType: 'json',
|
|
}
|
|
);
|
|
|
|
if (data.value == null) {
|
|
toast.error('Edit warren', {
|
|
description: error.value?.data ?? 'Failed to edit warren',
|
|
});
|
|
|
|
return {
|
|
success: false,
|
|
};
|
|
}
|
|
|
|
await refreshNuxtData('admin-resources');
|
|
|
|
toast.success('Edit warren', {
|
|
description: 'Successfully editd warren',
|
|
});
|
|
|
|
return {
|
|
success: true,
|
|
warren: data.value.data,
|
|
};
|
|
}
|