Unborked?
This commit is contained in:
parent
4275d51faf
commit
6529cb3810
|
@ -55,7 +55,7 @@ export function Routine(
|
|||
<main class='flex flex-col overflow-x-scroll'>
|
||||
<ul>
|
||||
{taskGroups[currentPhase.value].map((
|
||||
{ emoji, id, doneAt, index }: TaskWithIndex,
|
||||
{ emoji, id, description, doneAt, index }: TaskWithIndex,
|
||||
) => (
|
||||
<li
|
||||
role='button'
|
||||
|
@ -84,7 +84,7 @@ export function Routine(
|
|||
}}
|
||||
>
|
||||
{emoji ? `${emoji.trim()} ` : ''}
|
||||
{id.trim()}
|
||||
{description.trim()}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
|
|
@ -57,6 +57,14 @@ export const handler: Handlers<Task | null> = {
|
|||
return Response.redirect(url, 303)
|
||||
}
|
||||
},
|
||||
async PUT(req, _ctx) {
|
||||
if (req.headers.get('content-type')?.includes('json')) {
|
||||
const result = await createOrUpdate(
|
||||
TaskPayload.parse(await req.json()),
|
||||
)
|
||||
return new Response(JSON.stringify(result))
|
||||
}
|
||||
},
|
||||
async DELETE(req, _ctx) {
|
||||
// task: form or query params or json
|
||||
let data
|
||||
|
@ -67,7 +75,7 @@ export const handler: Handlers<Task | null> = {
|
|||
}
|
||||
console.log('delete task data:', data)
|
||||
const taskData = TaskModel.pick({ id: true }).parse(data)
|
||||
const result = await db.tasks.delete({ where: taskData })
|
||||
const result = await kv.delete(['task', taskData.id])
|
||||
await kv.set(['last_task_updated'], taskData.id)
|
||||
return new Response(JSON.stringify(result))
|
||||
},
|
||||
|
@ -95,9 +103,7 @@ export const handler: Handlers<Task | null> = {
|
|||
continue
|
||||
}
|
||||
|
||||
const task = await db.tasks.findFirst({
|
||||
where: { id: entry.value },
|
||||
})
|
||||
const task = (await kv.get(['task', entry.value])).value
|
||||
const chunk = `data: ${
|
||||
JSON.stringify({
|
||||
id: entry.value,
|
||||
|
@ -133,10 +139,12 @@ export const handler: Handlers<Task | null> = {
|
|||
const taskData = TaskModel.pick({ id: true }).safeParse(data)
|
||||
if (taskData.success) {
|
||||
return new Response(
|
||||
JSON.stringify(await db.tasks.findFirst({ where: taskData.data })),
|
||||
JSON.stringify((await kv.get(['task', taskData.data.id])).value),
|
||||
)
|
||||
} else {
|
||||
return new Response(JSON.stringify(await db.tasks.findMany({})))
|
||||
return new Response(
|
||||
JSON.stringify(Array.fromAsync(kv.list({ prefix: ['task'] }))),
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Handlers, PageProps } from '$fresh/server.ts'
|
||||
import { Task } from '@homeman/models.ts'
|
||||
import { Routine } from '@homeman/islands/Routine.tsx'
|
||||
import { db } from '@homeman/db.ts'
|
||||
import { kv } from '@homeman/db.ts'
|
||||
// import { db, kv, Todo, UserWithTodos } from '@homeman/models.ts'
|
||||
|
||||
interface Data {
|
||||
|
@ -10,7 +10,10 @@ interface Data {
|
|||
|
||||
export const handler: Handlers = {
|
||||
async GET(_req, ctx) {
|
||||
const tasks = await db.tasks.findMany({})
|
||||
const tasks = (await Array.fromAsync(kv.list({ prefix: ['task'] }))).map(
|
||||
(r) => r.value
|
||||
)
|
||||
console.log({ tasks })
|
||||
return ctx.render({ tasks })
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue