mirror of
https://github.com/shishantbiswas/bknd-examples.git
synced 2026-02-27 20:11:15 +00:00
26 lines
763 B
TypeScript
26 lines
763 B
TypeScript
import { getApi } from "../utils/bknd";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const body = await readBody(event);
|
|
const { action, data } = 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:
|
|
throw createError({ statusCode: 400, statusMessage: "Invalid Action" });
|
|
}
|
|
}); |