homeman-deno/routes/api/todo/done.ts

15 lines
457 B
TypeScript
Raw Normal View History

2024-01-11 18:57:29 -06:00
import { Handlers } from '$fresh/server.ts'
import { db, TodoModel } from '@homeman/models.ts'
const Model = TodoModel.pick({ id: true })
export const handler: Handlers = {
async POST(req, _ctx) {
const { id } = Model.parse(await req.json())
const todo = await db.todos.findFirst({ where: { id } })
todo.doneAt = new Date()
const newTodo = await db.todos.update({ where: { id }, data: todo })
return new Response(JSON.stringify(newTodo))
},
}