diff --git a/actions/sprints.ts b/actions/sprints.ts index bf7dac3..4b6acbf 100644 --- a/actions/sprints.ts +++ b/actions/sprints.ts @@ -12,6 +12,7 @@ import { updateSprintGoalSchema, } from '@/lib/schemas/sprint' import { enforceUserRateLimit } from '@/lib/rate-limit' +import { updateTaskStatusWithStoryPromotion } from '@/lib/tasks-status-update' async function getSession() { return getIronSession(await cookies(), sessionOptions) @@ -272,3 +273,31 @@ export async function completeSprintAction( revalidatePath(`/products/${sprint.product_id}/sprint`) return { success: true } } + +export async function setAllSprintTasksDoneAction( + sprintId: string, +): Promise<{ ok: true } | { ok: false; error: string }> { + const session = await getSession() + if (!session.userId) return { ok: false, error: 'Niet ingelogd' } + if (session.isDemo) return { ok: false, error: 'Niet beschikbaar in demo-modus' } + + const sprint = await prisma.sprint.findFirst({ + where: { id: sprintId, product: productAccessFilter(session.userId) }, + select: { id: true, product_id: true }, + }) + if (!sprint) return { ok: false, error: 'Sprint niet gevonden' } + + const tasks = await prisma.task.findMany({ + where: { sprint_id: sprintId, product_id: sprint.product_id }, + select: { id: true }, + }) + + await prisma.$transaction(async (tx) => { + for (const task of tasks) { + await updateTaskStatusWithStoryPromotion(task.id, 'DONE', tx) + } + }) + + revalidatePath(`/products/${sprint.product_id}/sprint`) + return { ok: true } +}