mirror of
https://github.com/shishantbiswas/bknd-examples.git
synced 2026-02-28 20:31:14 +00:00
init
This commit is contained in:
33
app/composables/useTodoActions.ts
Normal file
33
app/composables/useTodoActions.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
interface Todo {
|
||||
title: string | undefined;
|
||||
done: boolean | undefined;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export const useTodoActions = () => {
|
||||
const fetchTodos = () =>
|
||||
$fetch<{ limit: number; todos: Array<Todo>; total: number }>("/api/todo", {
|
||||
method: "POST",
|
||||
body: { action: "get" },
|
||||
});
|
||||
|
||||
const createTodo = (title: string) =>
|
||||
$fetch("/api/todo", {
|
||||
method: "POST",
|
||||
body: { action: "create", data: { title } },
|
||||
});
|
||||
|
||||
const deleteTodo = (id: number) =>
|
||||
$fetch("/api/todo", {
|
||||
method: "POST",
|
||||
body: { action: "delete", data: { id } },
|
||||
});
|
||||
|
||||
const toggleTodo = (todo: any) =>
|
||||
$fetch("/api/todo", {
|
||||
method: "POST",
|
||||
body: { action: "toggle", data: todo },
|
||||
});
|
||||
|
||||
return { fetchTodos, createTodo, deleteTodo, toggleTodo };
|
||||
};
|
||||
4
app/composables/useUser.ts
Normal file
4
app/composables/useUser.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const useUser = () => {
|
||||
const getUser = () => $fetch("/api/user");
|
||||
return { getUser };
|
||||
};
|
||||
Reference in New Issue
Block a user