15 lines
457 B
TypeScript
15 lines
457 B
TypeScript
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))
|
|
},
|
|
}
|