feat(ST-1112): wire story-promotion into saveTask and PATCH /api/tasks/:id
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8b779ccc0b
commit
eb27079ba7
5 changed files with 188 additions and 28 deletions
|
|
@ -9,6 +9,7 @@ import { SessionData, sessionOptions } from '@/lib/session'
|
|||
import { productAccessFilter } from '@/lib/product-access'
|
||||
import { requireProductWriter } from '@/lib/auth'
|
||||
import { taskSchema as sharedTaskSchema, type TaskInput } from '@/lib/schemas/task'
|
||||
import { updateTaskStatusWithStoryPromotion } from '@/lib/tasks-status-update'
|
||||
|
||||
async function getSession() {
|
||||
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||
|
|
@ -53,19 +54,30 @@ export async function saveTask(
|
|||
if (context.taskId) {
|
||||
const existing = await prisma.task.findFirst({
|
||||
where: { id: context.taskId, story: { product: scope } },
|
||||
select: { id: true, status: true },
|
||||
})
|
||||
if (!existing) return { ok: false, code: 403, error: 'forbidden' }
|
||||
|
||||
const task = await prisma.task.update({
|
||||
where: { id: context.taskId },
|
||||
data: {
|
||||
title,
|
||||
description: description ?? null,
|
||||
implementation_plan: implementation_plan ?? null,
|
||||
priority,
|
||||
...(status !== undefined ? { status } : {}),
|
||||
},
|
||||
select: { id: true, title: true, status: true },
|
||||
const taskId = context.taskId
|
||||
const statusChanged = status !== undefined && status !== existing.status
|
||||
|
||||
const task = await prisma.$transaction(async (tx) => {
|
||||
const updated = await tx.task.update({
|
||||
where: { id: taskId },
|
||||
data: {
|
||||
title,
|
||||
description: description ?? null,
|
||||
implementation_plan: implementation_plan ?? null,
|
||||
priority,
|
||||
},
|
||||
select: { id: true, title: true, status: true },
|
||||
})
|
||||
|
||||
if (statusChanged) {
|
||||
const result = await updateTaskStatusWithStoryPromotion(taskId, status, tx)
|
||||
return { id: result.task.id, title: result.task.title, status: result.task.status }
|
||||
}
|
||||
return updated
|
||||
})
|
||||
|
||||
revalidatePath(`/products/${context.productId}/sprint`)
|
||||
|
|
@ -222,7 +234,7 @@ export async function updateTaskStatusAction(id: string, status: 'TO_DO' | 'IN_P
|
|||
})
|
||||
if (!task) return { error: 'Taak niet gevonden' }
|
||||
|
||||
await prisma.task.update({ where: { id }, data: { status } })
|
||||
await updateTaskStatusWithStoryPromotion(id, status)
|
||||
|
||||
// /solo bewust niet revalideren: dat zou de page soft-navigaten en de
|
||||
// open SSE-stream sluiten. De Solo Paneel-flow leunt op optimistic
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue