feat: Todo altijd gekoppeld aan product backlog
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b541379964
commit
cb7eb36fbb
9 changed files with 128 additions and 46 deletions
|
|
@ -10,6 +10,7 @@ export default async function TodosPage() {
|
|||
const todos = await prisma.todo.findMany({
|
||||
where: { user_id: session.userId, archived: false },
|
||||
orderBy: { created_at: 'asc' },
|
||||
include: { product: { select: { name: true } } },
|
||||
})
|
||||
|
||||
const products = await prisma.product.findMany({
|
||||
|
|
@ -24,7 +25,14 @@ export default async function TodosPage() {
|
|||
<div className="p-6 max-w-2xl mx-auto w-full">
|
||||
<h1 className="text-xl font-medium text-foreground mb-6">Todo's</h1>
|
||||
<TodoList
|
||||
todos={todos.map(t => ({ id: t.id, title: t.title, done: t.done, created_at: t.created_at.toISOString() }))}
|
||||
todos={todos.map(t => ({
|
||||
id: t.id,
|
||||
title: t.title,
|
||||
done: t.done,
|
||||
created_at: t.created_at.toISOString(),
|
||||
product_id: t.product_id ?? null,
|
||||
product_name: t.product?.name ?? null,
|
||||
}))}
|
||||
products={products.map(p => ({
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { z } from 'zod'
|
|||
|
||||
const bodySchema = z.object({
|
||||
title: z.string().min(1, 'Titel is verplicht').max(500),
|
||||
product_id: z.string().min(1, 'Product is verplicht'),
|
||||
})
|
||||
|
||||
export async function POST(request: Request) {
|
||||
|
|
@ -21,9 +22,17 @@ export async function POST(request: Request) {
|
|||
return Response.json({ error: parsed.error.flatten() }, { status: 400 })
|
||||
}
|
||||
|
||||
const product = await prisma.product.findFirst({
|
||||
where: { id: parsed.data.product_id, user_id: auth.userId, archived: false },
|
||||
})
|
||||
if (!product) {
|
||||
return Response.json({ error: 'Product niet gevonden' }, { status: 404 })
|
||||
}
|
||||
|
||||
const todo = await prisma.todo.create({
|
||||
data: {
|
||||
user_id: auth.userId,
|
||||
product_id: parsed.data.product_id,
|
||||
title: parsed.data.title,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue