feat: implement core server actions for enhanced task operations
- Add updateItem server action with support for all metadata fields (title, description, completed, priority, dueDate, tags, notes) - Add deleteItem server action with proper revalidation - Add deleteList server action with cascade behavior (handled by Prisma schema) - Add updateList server action for renaming and color updates Requirements: 1.2, 1.3, 2.4, 2.5
This commit is contained in:
@@ -60,4 +60,62 @@ export async function toggleItem(itemId: string) {
|
||||
})
|
||||
revalidatePath(`/list/${item.listId}`)
|
||||
return updated
|
||||
}
|
||||
|
||||
export async function updateItem(
|
||||
itemId: string,
|
||||
data: {
|
||||
title?: string
|
||||
description?: string | null
|
||||
completed?: boolean
|
||||
priority?: 'low' | 'medium' | 'high'
|
||||
dueDate?: Date | null
|
||||
tags?: string[]
|
||||
notes?: string | null
|
||||
}
|
||||
) {
|
||||
const item = await prisma.item.findUnique({ where: { id: itemId } })
|
||||
if (!item) return null
|
||||
|
||||
const updated = await prisma.item.update({
|
||||
where: { id: itemId },
|
||||
data,
|
||||
})
|
||||
revalidatePath(`/list/${item.listId}`)
|
||||
return updated
|
||||
}
|
||||
|
||||
export async function deleteItem(itemId: string) {
|
||||
const item = await prisma.item.findUnique({ where: { id: itemId } })
|
||||
if (!item) return null
|
||||
|
||||
await prisma.item.delete({
|
||||
where: { id: itemId },
|
||||
})
|
||||
revalidatePath(`/list/${item.listId}`)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function deleteList(listId: string) {
|
||||
await prisma.list.delete({
|
||||
where: { id: listId },
|
||||
})
|
||||
revalidatePath('/')
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function updateList(
|
||||
listId: string,
|
||||
data: {
|
||||
title?: string
|
||||
color?: string
|
||||
}
|
||||
) {
|
||||
const updated = await prisma.list.update({
|
||||
where: { id: listId },
|
||||
data,
|
||||
})
|
||||
revalidatePath('/')
|
||||
revalidatePath(`/list/${listId}`)
|
||||
return updated
|
||||
}
|
||||
Reference in New Issue
Block a user