feat(ST-9pobw4w6): setAllSprintTasksDoneAction — alle sprint-taken atomair op DONE (#120)
Voegt setAllSprintTasksDoneAction toe aan actions/sprints.ts. De actie haalt alle taken op voor een sprint (via sprint_id + product_id), zet ze via een interactieve Prisma-transactie op DONE met updateTaskStatusWithStoryPromotion, en promoot parent-stories automatisch als alle taken DONE zijn. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
31dc429b61
commit
f09f5a2a06
1 changed files with 29 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ import {
|
||||||
updateSprintGoalSchema,
|
updateSprintGoalSchema,
|
||||||
} from '@/lib/schemas/sprint'
|
} from '@/lib/schemas/sprint'
|
||||||
import { enforceUserRateLimit } from '@/lib/rate-limit'
|
import { enforceUserRateLimit } from '@/lib/rate-limit'
|
||||||
|
import { updateTaskStatusWithStoryPromotion } from '@/lib/tasks-status-update'
|
||||||
|
|
||||||
async function getSession() {
|
async function getSession() {
|
||||||
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||||
|
|
@ -272,3 +273,31 @@ export async function completeSprintAction(
|
||||||
revalidatePath(`/products/${sprint.product_id}/sprint`)
|
revalidatePath(`/products/${sprint.product_id}/sprint`)
|
||||||
return { success: true }
|
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 }
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue