mirror of
https://github.com/shishantbiswas/bknd-examples.git
synced 2026-03-01 04:31:16 +00:00
refactor: using api routes for crud ops
This commit is contained in:
@@ -6,25 +6,25 @@ interface Todo {
|
||||
|
||||
export const useTodoActions = () => {
|
||||
const fetchTodos = () =>
|
||||
$fetch<{ limit: number; todos: Array<Todo>; total: number }>("/api/todo", {
|
||||
$fetch<{ limit: number; todos: Array<Todo>; total: number }>("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "get" },
|
||||
});
|
||||
|
||||
const createTodo = (title: string) =>
|
||||
$fetch("/api/todo", {
|
||||
$fetch("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "create", data: { title } },
|
||||
});
|
||||
|
||||
const deleteTodo = (id: number) =>
|
||||
$fetch("/api/todo", {
|
||||
$fetch("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "delete", data: { id } },
|
||||
});
|
||||
|
||||
const toggleTodo = (todo: any) =>
|
||||
$fetch("/api/todo", {
|
||||
$fetch("/todos", {
|
||||
method: "POST",
|
||||
body: { action: "toggle", data: todo },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user