diff --git a/actions/todos.ts b/actions/todos.ts index 1b717a8..92a0069 100644 --- a/actions/todos.ts +++ b/actions/todos.ts @@ -59,6 +59,26 @@ export async function archiveCompletedTodosAction() { return { success: true } } +export async function archiveSelectedTodosAction(ids: string[]) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + if (!ids.length) return { error: 'Geen todos geselecteerd' } + + const owned = await prisma.todo.findMany({ + where: { id: { in: ids }, user_id: session.userId }, + select: { id: true }, + }) + if (owned.length !== ids.length) return { error: 'Ongeldige selectie' } + + await prisma.todo.updateMany({ + where: { id: { in: ids }, user_id: session.userId }, + data: { archived: true }, + }) + revalidatePath('/todos') + return { success: true } +} + const promotePbiSchema = z.object({ todoId: z.string(), productId: z.string(),