import { Handlers } from '$fresh/server.ts' import { db, TodoModel } from '@homeman/models.ts' const Model = TodoModel.pick({ id: true }) async function markDone(id: string) { const todo = await db.todos.findFirst({ where: { id } }) todo.doneAt = new Date() return await db.todos.update({ where: { id }, data: todo }) } async function markNotDone(id: string) { return await db.todos.update({ where: { id }, data: { doneAt: null } }) } export const handler: Handlers = { async PUT(req, _ctx) { const { id } = Model.parse(await req.json()) return new Response(JSON.stringify(await markDone(id))) }, async DELETE(req, _ctx) { const { id } = Model.parse(await req.json()) return new Response(JSON.stringify(await markNotDone(id))) }, }