feat(ST-509): persist Todo description in create and update actions
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
318cb1e1f9
commit
856a051b2f
1 changed files with 8 additions and 2 deletions
|
|
@ -18,10 +18,12 @@ export async function createTodoAction(_prevState: unknown, formData: FormData)
|
||||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||||
|
|
||||||
const title = (formData.get('title') as string)?.trim()
|
const title = (formData.get('title') as string)?.trim()
|
||||||
|
const description = (formData.get('description') as string)?.trim() || null
|
||||||
const raw = (formData.get('productId') as string)?.trim()
|
const raw = (formData.get('productId') as string)?.trim()
|
||||||
const productId = (raw && raw !== 'all') ? raw : null
|
const productId = (raw && raw !== 'all') ? raw : null
|
||||||
|
|
||||||
if (!title) return { error: 'Titel is verplicht' }
|
if (!title) return { error: 'Titel is verplicht' }
|
||||||
|
if (description && description.length > 2000) return { error: 'Beschrijving is langer dan 2000 tekens' }
|
||||||
|
|
||||||
if (productId) {
|
if (productId) {
|
||||||
const product = await prisma.product.findFirst({
|
const product = await prisma.product.findFirst({
|
||||||
|
|
@ -30,7 +32,9 @@ export async function createTodoAction(_prevState: unknown, formData: FormData)
|
||||||
if (!product) return { error: 'Product niet gevonden' }
|
if (!product) return { error: 'Product niet gevonden' }
|
||||||
}
|
}
|
||||||
|
|
||||||
await prisma.todo.create({ data: { user_id: session.userId, product_id: productId, title } })
|
await prisma.todo.create({
|
||||||
|
data: { user_id: session.userId, product_id: productId, title, description },
|
||||||
|
})
|
||||||
revalidatePath('/todos')
|
revalidatePath('/todos')
|
||||||
return { success: true }
|
return { success: true }
|
||||||
}
|
}
|
||||||
|
|
@ -66,12 +70,14 @@ export async function updateTodoAction(_prevState: unknown, formData: FormData)
|
||||||
|
|
||||||
const id = (formData.get('id') as string)?.trim()
|
const id = (formData.get('id') as string)?.trim()
|
||||||
const title = (formData.get('title') as string)?.trim()
|
const title = (formData.get('title') as string)?.trim()
|
||||||
|
const description = (formData.get('description') as string)?.trim() || null
|
||||||
const raw = (formData.get('productId') as string)?.trim()
|
const raw = (formData.get('productId') as string)?.trim()
|
||||||
const productId = raw || null
|
const productId = raw || null
|
||||||
const done = formData.get('done') === 'on'
|
const done = formData.get('done') === 'on'
|
||||||
|
|
||||||
if (!id) return { error: 'Ongeldige todo' }
|
if (!id) return { error: 'Ongeldige todo' }
|
||||||
if (!title) return { error: 'Titel is verplicht' }
|
if (!title) return { error: 'Titel is verplicht' }
|
||||||
|
if (description && description.length > 2000) return { error: 'Beschrijving is langer dan 2000 tekens' }
|
||||||
|
|
||||||
const todo = await prisma.todo.findFirst({
|
const todo = await prisma.todo.findFirst({
|
||||||
where: { id, user_id: session.userId },
|
where: { id, user_id: session.userId },
|
||||||
|
|
@ -87,7 +93,7 @@ export async function updateTodoAction(_prevState: unknown, formData: FormData)
|
||||||
|
|
||||||
await prisma.todo.update({
|
await prisma.todo.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: { title, product_id: productId, done },
|
data: { title, description, product_id: productId, done },
|
||||||
})
|
})
|
||||||
revalidatePath('/todos')
|
revalidatePath('/todos')
|
||||||
return { success: true }
|
return { success: true }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue