warren creation / edit / deletion
This commit is contained in:
45
frontend/lib/api/admin/editWarren.ts
Normal file
45
frontend/lib/api/admin/editWarren.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user