refactor: using api routes for crud ops

This commit is contained in:
2026-02-17 04:35:23 +05:30
parent 74c47a7ff6
commit d39f0cc89d
3 changed files with 10 additions and 17 deletions

View File

@@ -0,0 +1,26 @@
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const { data, action } = body;
const api = await getApi({});
switch (action) {
case 'get':
const limit = 5;
const todos = await api.data.readMany("todos", { limit, sort: "-id" });
return { total: todos.body.meta.total, todos, limit };
case 'create':
return await api.data.createOne("todos", { title: data.title });
case 'delete':
return await api.data.deleteOne("todos", data.id);
case 'toggle':
return await api.data.updateOne("todos", data.id, { done: !data.done });
default:
return { path: action };
}
});